【发布时间】:2012-04-04 15:52:18
【问题描述】:
看看这个简单的页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body {padding:20px;}
#outer {background-color:#ff0000;}
#inner {width:500px; border:1px solid #0000ff;}
</style>
</head>
<body>
<div id="outer">
<div id="inner">
<p>Why the hell outer div bg color does not expand?</p>
<p>Why the hell outer div bg color does not expand?</p>
<p>Why the hell outer div bg color does not expand?</p>
</div>
</div>
</body>
</html>
当浏览器页面缩小到<div id="inner">的宽度以下(即本例中的500px)并且然后您将浏览器页面向右滚动,您将看到内部 div 的右侧不再有红色背景了:
你知道如何修复outer <div>的背景,使其永远不会缩小到inner <div>的宽度以下吗???(我仍然需要outer div背景来扩展到完整的浏览器宽度,所以它也不能设置为width:500px;)。
编辑: 换句话说,我希望看到外部 div 的红色背景色来填充内部 div 的总 500px 宽度,而不是缩小到浏览器大小,离开右侧没有红色背景的内部 div。为了做到这一点,我不能简单地将外部 div 设置为 500px,因为当浏览器展开时,我也需要红色背景颜色来展开。
【问题讨论】:
标签: css background expand