欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

知识点-------布局总括~~~~flex布局-grid布局-圣杯布局

程序员文章站 2022-03-25 13:49:30
...

flex布局:(导航布局)

<!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>flex布局</title>
  <style lang="">
    header {
      display: flex;
      background-color: antiquewhite;
    }
     header>div{
       padding:5px 10px;
       background-color: blueviolet;
     }
    header>div:last-child {
      margin-left: auto;
    }
  </style>
</head>

<body>
  <header>
    <div>HOME</div>
    <div>SEARCH</div>
    <div>LOGOUT</div>
  </header>
</body>

</html>

 grid布局:(简单导航布局)

<!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>grid布局</title>
  <style>
    header {
      display: grid;
      grid-template-columns: repeat(10,
        1fr);
        /* 10px repeat(8,1fr) 20px  总宽先减去 10 和 20 剩余宽 ➗ 8 ,即剩余的每份宽*/
        /* repeat(10,1fr)重复项时使用最优,10格,每格为1fr(倍)即总宽➗10即每份的宽 */
      background-color: antiquewhite;
    }
    header div {
      text-align: ceenter;
      background-color: aqua;
      padding: 10px 20px;
    }
    header>div:last-child {
      grid-column:10;
    }
  </style>
</head>

<body>
  <header>
    <div>首页</div>
    <div>个性化</div>
    <div>登陆</div>
    <div>推荐</div>
    <div>定制</div>
  </header>
</body>

</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>圣杯布局</title>
  <style>
    .w200 {
      width: 100px;
      height: 500px;
      background-color: green;
    }

    .parent {
      display: flex;
      flex-direction: row;
      width: 100%;
    }

    .center {
      width: -webkit-calc(100% - 200px);
      height: 500px;
    }
  </style>
</head>

<body>
  <div class="parent">
    <div class="left w200">左边</div>
    <div class="center">中间</div>
    <div class="right w200">右边</div>
  </div>



</body>

</html>