关于float的自动换行问题
程序员文章站
2022-05-31 18:04:53
...
首先设置的几个float属性遇到超过父容器的情况下会自动换行
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<style>
.box {
width: 100px;
height: 700px;
margin: 0 auto;
border: 1px solid red;
}
.s-left{
width: 60px;
height: 100px;
background-color: #FF0000;
float: left;
}
.s-right
{
width: 60px;
height: 100px;
background-color: yellow;
float: right;
}
</style>
</head>
<body>
<div class="box">
<div class="s-left"></div>
<div class="s-right"></div>
</div>
</body>
</html>
其次如果float属性遇到了没有定义float属性的块元素会自动换行
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<style>
.box {
width: 700px;
height: 700px;
margin: 0 auto;
border: 1px solid red;
}
.s-left{
width: 100px;
height: 100px;
background-color: #FF0000;
float: left;
}
.s-center{
width: 100px;
height: 100px;
background-color: pink;
}
.s-right
{
width: 100px;
height: 100px;
background-color: yellow;
float: right;
}
</style>
</head>
<body>
<div class="box">
<div class="s-left"></div>
<div class="s-center"></div>
<div class="s-right"></div>
</div>
</body>
</html>
上一篇: Textarea 自动换行实现