3

<span>我在使用标签时遇到 css 内联/块问题。在此处输入图像描述

在此处输入图像描述

正如您从图像中看到的那样,当您将鼠标悬停在第三条消息上时,删除/回复控件会弹出,我不希望他们将内容下推。我怎样才能做到这一点?

这是我的 CSS 代码:

ul.inbox {
    width: 100%;
    list-style-type: none;
}

.unread {
    border: 1px solid #999 !important;
    background: #eee url("new.png") no-repeat !important;
    background-position: left center !important;
}

li span.hidden {
    clear: both;
    visibility: hidden;
}

li span.messageControls {
    clear: both;
    float: right;
    display: inline;
}

li span.messageControls a {
    padding: 5px 5px 0 0;
    font-size: 12px;
    color: #06c;
}

li.message {
    background: #eee;
    border: 1px solid #ddd;
    list-style-type: none;
    display: block;
    margin: 0 0 10px;
    padding-left: 30px;
    background-position: left center;
}

li.message:hover {

}

li.message a {
    text-decoration: none;
}

li {
    overflow: hidden;
}

li span.from {
    margin: 5px 0 5px 5px;
    font-family:"Open Sans",sans-serif;
    font-size: 14px;
    color: #666;
    float: left;
    font-weight: 700;
}

li span.date {
    margin: 5px 5px 5px 0;
    font-size: 12px;
    float: right;
    color: #06c;
}

li p.subject {
    margin: 5px 0 5px 5px;
    font-size: 14px;
    color: #666;
    clear: both;
    font-weight: 700;
}

li p.preview {
    margin: 5px 0 5px 5px;
    font-size: 12px;
    color: #999;
}

还有我的“收件箱”代码:

<ul class="inbox">
    <li id="1001843" class="message " onmouseout="document.getElementById('1001843MC').className='hidden'" onmouseover="document.getElementById('1001843MC').className='messageControls'" onclick="ajaxMessage(1001843);">
        <span class="from">Michael‌·Norris</span> <span class="date">Yesterday‌·21:18</span> <span id="1001843MC" class="hidden"><a href="compose.php?id=&to=">Reply</a> &nbsp; <a href="update.php?id=&action">Delete</a></span>

        <p class="subject">gjhgjhg</p>

        <p class="preview">jhgjhgjhg</p>
    </li>

    <li id="1001842" class="message " onmouseout="document.getElementById('1001842MC').className='hidden'" onmouseover="document.getElementById('1001842MC').className='messageControls'" onclick="ajaxMessage(1001842);">
        <span class="from">Michael‌·Norris</span> <span class="date">Yesterday‌·21:18</span> <span id="1001842MC" class="hidden"><a href="compose.php?id=&to=">Reply</a> &nbsp; <a href="update.php?id=&action">Delete</a></span>

        <p class="subject">gfhjgjfdhsgf</p>

        <p class="preview">gj‌·hg</p>
    </li>

    <li id="1001841" class="message " onmouseout="document.getElementById('1001841MC').className='hidden'" onmouseover="document.getElementById('1001841MC').className='messageControls'" onclick="ajaxMessage(1001841);">
        <span class="from">Michael‌·Norris</span> <span class="date">Yesterday‌·20:17</span> <span id="1001841MC" class="hidden"><a href="compose.php?id=&to=">Reply</a> &nbsp; <a href="update.php?id=&action">Delete</a></span>

        <p class="subject">gjhgjhg</p>

        <p class="preview">jhgjhgjhg</p>
    </li>
</ul>

在这里小提琴:http: //jsfiddle.net/Er73L/

4

4 回答 4

3

您需要clear正确设置属性以实现您想要的行为,而不是clear: both盲目使用。

我对您的 CSS 做了两处更改:

li span.messageControls {
    clear: right; /* was clear: both; */
    float: right;
    display: block; /* was display: inline */
}

li p.subject {
    margin: 5px 0 5px 5px;
    font-size: 14px;
    color: #666;
    clear: left; /* was clear: both; */
    font-weight: 700;
}

这是一个工作示例。我还建议您阅读文档

于 2013-01-18T00:43:28.830 回答
1

这是我建议您解决此问题的方法:http: //jsfiddle.net/Er73L/1/

这是与原始 CSS 相比的差异:http ://www.diffchecker.com/3tKbEnCe

li span.messageControls {
    position: absolute;
    right: 0;
    top: 1em;
}

li.message {
    background: #eee;
    border: 1px solid #ddd;
    list-style-type: none;
    display: block;
    margin: 0 0 10px;
    padding-left: 30px;
    background-position: left center;
    position: relative;  // NEW LINE
}
于 2013-01-18T00:43:32.610 回答
1

简单的修复,只需使用clear:left而不是clear:both这样:

li p.subject {
    margin: 5px 0 5px 5px;
    font-size: 14px;
    color: #666;
    clear:left;
    font-weight: 700;
}

小提琴

于 2013-01-18T00:46:48.433 回答
0

另一种选择是绝对定位跨度元素。只需将此行添加到 CSS 的底部并根据需要进行调整...

.messageControls{width:100px;border:1px solid red;position:absolute;right:0;margin-top:20px;}

http://jsfiddle.net/nYCsx/1/

于 2013-01-18T00:53:01.673 回答