几年前曾有这样一个问题被提出:如果一个元素的宽度大于屏幕宽度,那么其他块级元素(如h1等)不会扩展以匹配该元素(请参见fiddle,在宽元素出现后,h1的宽度不会改变):
function addElement(){
$("#para").after('<div class="wide">Wide</div>');
$("a").fadeOut();
// $("h1").width($(".wide").width()); // <-- trying to avoid needing this
}
body {margin:0; padding:0}
h1 {background-color:#eee}
.wide {background-color:#00c; color:#fff; width:110%; margin-top:1em; margin-bottom:1em}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1>Header 1</h1>
<p id="para">
<a href="#" onclick="addElement(); return false;">Add wide element</a>
</p>
如果没有,我很乐意删除这个问题,但无法想到一种方法来重新引起对旧问题的关注,因为现在可能存在更好的解决方案。