HTML元素背景水平滚动bug

时间:2014-10-09 12:17:54

标签: html css

这是我的css:

.content {
    background-color: #fff;
    position: relative;
    margin: 45px 10px 0px 10px;
}
#logData {
    font-family: "Courier New";
    font-size: 13px;
    line-height: 1.3;
    margin-left: 0px;
    color: #000;
}
.logMess {
    color:#000;
    padding: 4px 5px 2px 3px;
    min-width: 100%;
}
.logMessBg {
    color:#000;
    padding: 4px 5px 2px 3px;
    min-width: 100%;
    background: rgb(245, 245, 245);
}

这是HTML:

<div class="content">
    <div id="logData">
        <p class="logMessBg">some loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text</p>
        <p class="logMess">some loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text</p>
    </div>
</div>

问题在于水平滚动。因为backgroud在<p class="logMessBg">文本结束时结束,但我希望它在最长的<p>文本结束时结束。所以,我想要所有宽度的背景宽度。

这是屏幕: enter image description here

1 个答案:

答案 0 :(得分:2)

display: inline-block;添加到.content#logData,如下所示:

JSFiddle - DEMO

.content {
    background-color: #fff;
    position: relative;
    margin: 45px 10px 0px 10px;
    display: inline-block;
}