21-浮动对db和dib的影响

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>demo</title>
<style>
*{margin: 0;padding: 0;}
.box{
width: 100%;
height: 500px;
box-sizing: border-box;
border: 5px solid #000;
}
.left{
width: 100px;
height: 100px;
background: red;
float: left;
}
.middle{
width: 100%;
height: 100px;
background: blue;
display: inline-block;
}
</style>
</head>
<body>
<div class="box">
<div class="left"></div>
<div class="middle"></div>
</div>
</body>
</html>
  1. 当 .left 浮动时:
    • db按照原来一样的布局,但是文字会被挤压,不适合用于居中。
    • dib会被.left挤出来,当dib宽度不够另起一行,db不会。