欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

浮动与清除浮动

程序员文章站 2022-03-07 18:26:01
...
元素的浮动是指设置了浮动属性的元素会脱离标准普通流的控制,移动到其父元素中指定位置的过程。在CSS中,通过float属性来定义浮动,其基本语法格式如下:选择器{float:属性值;}
非常实用的是可以将一个父类盒子中的多个子类盒子在一行显示。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
/*div{
width: 200px;
height: 200px;
}*/
.one{
width: 200px;
height: 200px;
background-color: blue
float: left;
}
.two{
width: 200px;
height: 200px;
background-color: yellow;
float:left;
}
/*.three{
background-color: green;
}*/
.three{
width: 200px;
height: 200px;
background-color: green;
float: left;
}
.father{
width: 600px;
height: 800px;
background-color: red;
}
</style>
</head>
<body>
<div class="father">
<div class="one">one</div>
<div class="two">two</div>
<span class="three">three</span>
</div>
</body>
</html>

结果如下:
浮动与清除浮动

清除浮动用overflow:hidden和clear:both来实现。

相关标签: HTML