gpt4 book ai didi

html - 为什么div不在两个div之间

转载 作者:太空宇宙 更新时间:2023-11-04 00:48:30 25 4
gpt4 key购买 nike

我刚开始学习 css,我想在边缘制作两个 div 和类名为 wide 的 div 我想将它居中,所以我给它绝对位置和 left:50% 但它不起作用

.container{
background-color:#6699;
width: 900px;
height:600px;
margin:20px auto;
position: relative
}

.tall{
background-color:#993399;
width: 200px;
height:100%;
float: right
}

.wide{
background-color:#6600cc;
width:200px;
height:200px;
position: absolute;
left:50%
}


.tall2{
background-color:#006699;
width:200px;
height:100%;
}
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="float.css">
</head>
<body>
<div class="container">
<div class="tall"></div>
<div class="wide"></div>
<div class="tall2"></div>

</div>
</body>

最佳答案

目前还不完全清楚您要做什么,但您很可能会通过 flexgrid 布局获得更好的服务。对于这样的布局, float 通常不再是最佳实践。

你可以尝试这样的事情:


.container {
display: flex;
}

.tall, .tall2 {
width: 200px;
}

.wide {
flex: 1;
}

关于html - 为什么div不在两个div之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56552947/

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