gpt4 book ai didi

html - float div的CSS重叠

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

我在使用 float div 时遇到问题。谁能帮帮我。

一共有7个盒子,分3行。

1/3 2/3
1/3 1/3 1/3
1/3 2/3

但是,它们重叠而不是给我填满页面的图 block 。你能帮忙吗?

#tl_square 
{ max-width: 500px;
width: 33.3333%;
float: left;
padding: 2%;
background-color: blue;
}
#tr_square {
max-width: 1000px;
width: 66.6667%;
float: right;
padding: 1%;
background-color: yellow;
}
#ml_square {
max-width: 500px;
width: 33.3333%;
float: left;
padding: 2%;
background-color: black;
}
#mm_square {
max-width: 500px;
width: 50%;
float: left;
padding: 2%;
}
#mr_square {
max-width: 500px;
width: 50%;
float: right;
padding: 2%;
background-color: black;
}
#m_nested_square {
max-width: 1000px;
width: 66.6667%
float: right;
}
#bl_square {
max-width: 500px;
width: 33.3333%;
float: left;
max-height: 500px
height: 33.3333%;
padding: 2%;
background-color: blue;
}
#br_square {
max-width: 1000px;
width: 66.6667%;
float: right;
max-height: 500px
height: 33.3333%;
padding: 1%;
background-color
}
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- This sets the website, on any device, to fit the size of the screen. -->
<title>jamesnovis.com</title>
</head>
<body>

<!-- The top boxes -->
<div id="tl_square">
</div>

<div id="tr_square">
</div>


<!-- The middle boxes -->
<div id="ml_square">
</div>

<!-- These are nested divs -->
<div id="m_nested_square">
<div id="mm_square">
</div>

<div id="mr_square">
</div>
</div>

<!-- The bottom boxes -->
<div id="bl_square">
</div>

<div id="br_square">
</div>

</body>
</html>

最佳答案

你应该使用 clearfix cause float 和 border-box-model 来填充/边距

* {
box-sizing: border-box;
}

.clearfix:after {
content: ".";
clear: both;
display: block;
visibility: hidden;
height: 0px;
}

然后使用 66.6666% 而不是 66.6667%。这个世界上有些浏览器不理解背后的含义......

在此之后,您只需要用 clearfix 分类元素包裹 float 的“对”

https://jsfiddle.net/p82p63zo/

关于html - float div的CSS重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35554421/

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