3 回答
已采纳
西兰花伟大炮
TA贡献376条经验 获得超318个赞
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .container{ height: auto; width: 400px; margin: 100px auto; border: 2px dotted red; } .item{ float: left; width: 50px; height: 50px; background: yellow; margin-right: 10px; } /*.clearfix::after{ content: ""; height: 0; clear: both; display: block; }*/ .last{ clear: both; } </style> </head> <body> <div class="container clearfix" > <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="last"></div> </div> </body> </html>
两种方法,一种伪类,一种是在末尾添加空元素,欢迎采纳
frece
TA贡献36条经验 获得超15个赞
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> .fl{float: left;} .fr{float: right;} .square{width: 200px; height: 200px; border: 1px solid #0000ff;} .clear{clear: both;} </style> </head> <body> <div> <div class="square fl">square1</div> <div class="square fr">square2</div> <div class="clear"></div> </div> <label>test text</label> </body> </html>
大型项目里都会定义一个 .clear 的样式 需要的时候直接用,上边代码你可以把<div class="clear"></div>去掉看看区别
一般情况下, 有浮动必有clear
- 3 回答
- 0 关注
- 1351 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消