我有一个DIV,它的宽度固定为960像素,嵌套容器没有特定的宽度,因此它们会拉伸到父容器。是否可以在不移除外部容器的情况下,将内部容器拉伸到整个页面宽度,同时内容应该与外部容器一样宽。
以下是一个小例子:
+------------------------------------------------+
| browser window (100%) |
| |
| +-----------------------------------+ |
| | (A) inner container (960px) | |
| | | |
|*****|***********************************|******|
| | (B) | |
| | | |
| | this should stretch to 100% of | |
| | body and have inner width of | |
| | of 960px (or the same as | |
| | closest parent) | |
| | | |
|*****|***********************************|******|
| | | |
| +-----------------------------------+ |
| |
+------------------------------------------------+
这么做的原因是我需要指定块的某些背景,但如果我删除指定固定宽度的外部容器,则会遇到问题。
更新:内部容器(B)应位于容器(A)内,如下所示:
<div class="container" style="width:960px">
<div class="box">
This box should stretch to 100% of page and must have non-fixed height.
</div>
</div>
页面上应该有多个容器,其中一些应该可以拉伸,而另一些则不能。绝对定位会破坏文档的正常流程,并导致后面的容器与前面的容器重叠。