伪元素:before和:after的简单应用——清除浮动
Posted wuaidongfang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了伪元素:before和:after的简单应用——清除浮动相关的知识,希望对你有一定的参考价值。
html代码:
<!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>demo</title> <link rel="stylesheet" href="https://cdn.bootcss.com/normalize/8.0.0/normalize.min.css"> <link rel="stylesheet" href="css/main.css"> </head> <body> <div class="nav"> <div class="container clear-float" > <div class="fl"> <span>首页</span> </div> <div class="fr"> <span>item</span> <span>item</span> <span>item</span> <span>item</span> <span>item</span> </div> </div> </div> </body> </html>
CSS代码:
.container{ display: block; max-width: 1080px; margin: 0 auto; } .fl{ float: left; } .fr{ float: right; } .clear-float:after, .clear-float:before{ content: " "; display: block; clear:both; }
以上是关于伪元素:before和:after的简单应用——清除浮动的主要内容,如果未能解决你的问题,请参考以下文章
[ css 伪元素 :before :after ] css中before, after伪元素特性表现解释和实例