gpt4 book ai didi

html - 为什么负边距底部使列高度相等?

转载 作者:行者123 更新时间:2023-11-28 06:20:32 25 4
gpt4 key购买 nike

下面的css可以让三列都等高,我想知道为什么?

<html>
<style>
body,p{
margin:0;
padding:0;
}
#wrap{
overflow:hidden;
width:1200px;
margin:0 auto;
}
#left,#center,#right {
margin-bottom:-200px;
}
#left {
float:left;
width:300px;
background:#777;
}
#center {
float:left;
width:300px;
background:red;
}
#right {
float:left;
width:300px;
background:green;
}
p {color:#FFF;text-align:center}
</style>
<body>
<div id="wrap">
<div id="left">
<p style="height:250px">style="height:250px"</p>
</div>
<div id="center">
<p style="height:300px">style="height:300px"</p>
</div>
<div id="right">
<p style="height:400px">style="height:400px"</p>
</div>
</div>
</body>
</html>

所有列的高度都是 200px。 enter image description here

为什么显示出来的效果不是这个?

enter image description here

因为 200=400-200 ,100=300-200,50=250-200??

这里的 margin-bottom:-200px; 是什么意思?
请画图详细说明原理。

最佳答案

这是因为 css 中的“wrap”类。我做了一个 jsfiddle here .我所做的唯一更改是删除溢出元素。HTML(未更改):

 <body>
<div id="wrap">
<div id="left">
<p style="height:250px">style="height:250px"</p>
</div>
<div id="center">
<p style="height:300px">style="height:300px"</p>
</div>
<div id="right">
<p style="height:400px">style="height:400px"</p>
</div>
</div>
</body>

CSS:

body,p{
margin:0;
padding:0;
}
#wrap{

width:1200px;
margin:0 auto;
}
#left,#center,#right {
margin-bottom:-200px;
}
#left {
float:left;
width:300px;
background:#777;
}
#center {
float:left;
width:300px;
background:red;
}
#right {
float:left;
width:300px;
background:green;
}
#right2 {
float:left;
width:300px;
background:blue;
}
p {color:#FFF;text-align:center}

关于html - 为什么负边距底部使列高度相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35621953/

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