如果你可以用你的设计做到这一点,只要把你的头的div到四溢的div并使其自动调整:
HTML:
<div id="content">
<div id="header">
<p>HEADER</p>
</div>
LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG CONTENT
</div>
CSS:
#header {
left:0px;
right:0px;
top:0px;
background: red;
}
#content {
width:1000px;
white-space: nowrap;
}
https://jsfiddle.net/p7m8wg48/
或制作包装:
HTML:
<div id="bodyClass">
<div id="header">
<p>HEADER</p>
</div>
<div id="content">
LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG CONTENT
</div>
</div>
CSS:
#bodyClass{
width:1000px;
}
#header {
left:0px;
right:0px;
top:0px;
background: red;
}
#content {
white-space: nowrap;
}
https://jsfiddle.net/dLmt1Ley/
编辑: RE:In your first suggestion, why did you put a fixed width? If I removed the fixed width the gap returns.
那是因为你不能填充设置元素的一个未定义的边缘。宽度固定在类似于before
的状态。溢出的内容调整实际宽度,但需要设置。
我知道你不欠我一个downvote的解释,但我想知道你为什么downvote我,所以我可以改善我的问题。 – Tuco