本教程操作环境:windows10系统、bootstrap3.3.7版、dell g3电脑
bootstrap清除浮动的类名是什么我们知道,在静态页面的编写中,清除浮动是一件很繁琐的事情。
所以一般的css框架都会有用来清除浮动的样式。
在bootstrap中,这个样式叫 clearfix.
只要在需要清除浮动的元素的父元素加上clearfix就可以了。
clearfix用于通过将.clearfix添加到父元素来轻松清除浮点数
语法类似:
<div class="clearfix">...</div>
示例如下:
新建一个html文件,命名为test.html,用于讲解bootstrap中清除浮动使用哪个类。使用link标签加载bootstrap.min.css文件。
在div标签内,再使用div创建两行文字。给外层div添加class属性,并通过class设置它的宽度为350px,高度为100px,背景颜色为灰色。
在内层两个div之前,再添加一个div,并给它添加清除浮动类名clearfix,实现上下两个div的浮动相互不影响。
<!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> <link rel="stylesheet" href="js/bootstrap.min.css"></head><body> <style> .mytest{ width:400px; height:50px; background:#ccc; } </style> <div class="mytest"> <div class="pull-left">测试一</div> <div class="clearfix"></div> <div class="pull-left">测试二</div> </div></body></html>
在浏览器打开test.html文件,查看实现的效果。
相关推荐:bootstrap教程
以上就是bootstrap清除浮动的类名是什么的详细内容。
