float
This commit is contained in:
93
csspress/demo/clearfloat.html
Normal file
93
csspress/demo/clearfloat.html
Normal file
@@ -0,0 +1,93 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.box {
|
||||
width: 1000px;
|
||||
height: 300px;
|
||||
background: gold;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.box1 {
|
||||
/* width:60px;
|
||||
height: 60px; */
|
||||
background: red;
|
||||
/* background: rgba(255, 0, 0, 0.363); */
|
||||
/* float: left; */
|
||||
|
||||
|
||||
}
|
||||
|
||||
.box2 {
|
||||
width: 120px;
|
||||
height: 80px;
|
||||
background: gray;
|
||||
border: 1px solid pink;
|
||||
color: white;
|
||||
/* float:right */
|
||||
float: left;
|
||||
}
|
||||
|
||||
.box4 {
|
||||
width: 120px;
|
||||
height: 80px;
|
||||
background: blue;
|
||||
border: 1px solid pink;
|
||||
/* clear: left;
|
||||
这是哪个元素需要清除浮动哪个元素加clear
|
||||
*/
|
||||
}
|
||||
|
||||
.boxes{
|
||||
overflow: auto;
|
||||
/*
|
||||
这是通过Overflow:auto 清除浮动
|
||||
*/
|
||||
}
|
||||
.blank{
|
||||
clear:left
|
||||
}
|
||||
/*
|
||||
在浮动元素最后面加一个空的div 附上clear属性清除浮动
|
||||
*/
|
||||
|
||||
/* .boxes:after {
|
||||
content: '.';
|
||||
height: 0;
|
||||
display: block;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
这是通过伪类清除浮动,必须加上content:"." 否则不起作用
|
||||
*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="box">
|
||||
<div class="boxes clearfix">
|
||||
<div class="box1">asaaaa</div>
|
||||
<div class="box2"></div>
|
||||
|
||||
<div class="box2">4</div>
|
||||
<div class="box2 blankdiv">5</div>
|
||||
<!-- <div class="box2" style="height: 180px;">6</div> -->
|
||||
<div class="blank"></div>
|
||||
</div>
|
||||
<div class="box4"></div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user