gpt4 book ai didi

css - 使 div 在父级内部 100% 宽度,而不是父级 div

转载 作者:技术小花猫 更新时间:2023-10-29 10:22:43 24 4
gpt4 key购买 nike

我想让我的内部 div 成为主体宽度的 100%,而不是父 div 的 100%。这可能吗?

布局看起来像这样:

<body>
<div> /** Width:900px; **/
<div> /** This I want 100% of BODY, not of parent div **/

</div>
</div>
</body>

最佳答案

我希望你看起来是这样的............请参阅DEMO

UPDATED DEMO 2 AS PER YOUR CURRENT REQUIREMENTS

CSS

    .parent {
background:red;
width:900px;
margin:0 auto;
padding:10px;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}

.inner {
background:green;
height:100px;
position:absolute;
left:0;
right:0;
}

.child {
height:100px;
background:black;
margin:10px 0;
}

------------**

第二个答案没有定位但有一些我在这里使用的技巧所以请检查下面提到的代码和演示:-

HTML

<body>
<div class="parent"> /** Width:900px; **/
<div class="child"></div>
</div>
<div class="inner"> /** This I want 100% of BODY, not of parent div **/</div>
<div class="parent">
<div class="child"></div>
<div class="child"></div>
</div>
</body>

CSS

.parent {
background:red;
width:900px;
margin:0 auto;
padding:10px;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}

.inner {
background:green;
height:100px;
}

.child {
height:100px;
background:black;
margin:10px 0;
}

DEMO

关于css - 使 div 在父级内部 100% 宽度,而不是父级 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13511249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com