hooyantsing's Blog

P77_7_使用AFTER伪元素清除浮动影响

字数统计: 98阅读时长: 1 min
2020/04/14

P77 7 使用AFTER伪元素清除浮动影响

实战案例

cd7263bc4100a1277d481d34894b68a7.png

代码:

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
CSS:
main {
    border: solid 3px black;
    margin: 0 auto;
    padding: 20px;
}
main::after {
    content:"",
    clear: both;
    display: block;
}
div {
    width: 300px;
    height: 300px;
    box-sizing: border-box;
}
div:nth-of-type(1) {
    border: solid 3px red;
    float:left;
}
div:nth-of-type(2) {
    background: blue;
    float:right;
}

HTML:
<main>
    <div></div>
    <div></div>
</main>
CATALOG