gpt4 book ai didi

css - 父 div 内的 3 个 div 不自动调整大小

转载 作者:太空宇宙 更新时间:2023-11-03 22:08:13 26 4
gpt4 key购买 nike

我是网页设计的新手,我想知道如何做这样的事情:

..........................LEFT --- CENTER ---- RIGHT..........................

Its one parent div in the center of the window, with 3 divs inside like columns. I want them to be dynamic, so they always scale to the browser window.

This is how it looks now.

My current HTML:

<div id="container_m">
<div id="left">
<p>My name is Barnabas</p>
</div>
<div id="right">
<p>Till salu</p>
</div>
<div id="center">
<p>Senaste nytt</p>
</div>
</div>

我当前的 CSS:

#container_m
{
position:absolute;
height: 40%;
width: 60%;
left: 20%;
top: 45%;
background-color:rgba(0,0,0,0.2);

}

#left
{
position: relative;
height: 100%;
width: 33%;
float: left;
background-color: blue;


}
#right
{
position: relative;
height: 100%;
width: 33%;
float: right;
background-color: green;
}

#center
{
position: relative;
height: 100%;
width: 33%;
margin:0 auto;
background-color: yellow;
}

最佳答案

float div 有时会破坏父 div 的自动调整大小。为了确保父 div 的适当自动调整大小,我所做的是将其添加到父 div,就在最后一个 float 子元素的后面:

<div style="clear: both;"></div>

这可能是一个肮脏的修复或其他什么,但它确保父 div 始终与其子 div 一起调整大小。

关于css - 父 div 内的 3 个 div 不自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3694295/

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