利用 :after 伪类来实现清除浮动

 

<!doctype html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title></title>

</head>

 

<style>

 

*{padding:0px;margin:0px;}

ul,li{list-style:none;}

.nav li{float:left;}

.test{height:100px;width:100px;background:orange;}

/* 重点是下面这代码 */

.nav:after{content:"";clear:both;height:0;display:block;}   

 

</style>

 

<body>

    

<div class="nav">

    <li>标签1</li>

    <li>标签2</li>

    <li>标签3</li>

    <li>标签4</li>

</div>

 

<div class="test"></div>

 

</body>

 

</html>

 

相关文章:

  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案