在php循环中显示正确的问题

时间:2016-02-15 10:28:27

标签: php html css twitter-bootstrap yii

我为我的应用程序创建了一个通知区域。我想在每个标签的右侧显示一个小红色的子弹。

我用绝对的位置工作,现在的东西就是子弹出现在所有页面上。

这是我的代码和我的CSS:

how it looks

.read-button{
    font-size: 8px;
    color: #FC5D5D;
    display:block;
    position:absolute;
    right:20px;
    padding-top: 15px;
}

我的PHP:

  <?php foreach($messages as $mess) { ?>
    <?php
    $from_user = $user->isClient()?User::findIdentity($mess->message_filmmaker_id):User::findIdentity($mess->message_client_id);
    $from_name = $from_user->first_name." ".$from_user->last_name;

    $url = "#";
    if ($user->isClient()) $url = Url::to(['client/view-project', 'project_id' => $mess->project_id, 'filmmaker_id' => $from_user->id]);
    elseif ($user->isFilmmaker()) $url = Url::to(['filmmaker/view-project', 'project_id' => $mess->project_id]);
    ?>


    <a class="content" href="<?= $url ?>">
        <div class="notification-item">
            <div class="item-pic float-left"><div class="avatar"><?= Html::img(['/site/get-avatar', 'user_id' => $from_user->id]) ?></div></div>
            <div class="item-info float-left">
                <div><?= $from_name ?> - Il y a <?= $mess->getElapsedTime() ?></div>
                <div><?= $mess->message_text ?></div>
            </div>
            <div class="read-button float-right">
                <span class="glyphicon glyphicon-cd" aria-hidden="true"></span>
            </div>
            <div class="clear-both"></div>
        </div>
    </a>

    <li class="divider"></li>
<?php } ?>

1 个答案:

答案 0 :(得分:0)

绝对位置适用于具有绝对或相对位置的父级。 尝试设置位置:相对于notification-item类,绝对位置相对于此父元素。