伪元素: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>demotitle>
  <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>itemspan>
          <span>itemspan>
          <span>itemspan>
          <span>itemspan>
          <span>itemspan>
        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;
}

 

转载于:https://www.cnblogs.com/wuaidongfang/p/9984485.html

你可能感兴趣的:(伪元素:before和:after的简单应用——清除浮动)