Css盒模型、两栏布局、三栏布局、圣杯布局、双飞翼布局

一.Css盒模型

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS盒模型</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box{
      width: 400px;
      height: 400px;
      margin: 0 auto;
      background-color: skyblue;
      /* 内边距padding   margin外边距同理 上右下左各25px */
      /* padding-top: 25px; 
      padding-right: 25px;
      padding-bottom: 25px;
      padding-left: 25px; */
      /* 上 (左右) 下  两个值 (上下) (左右)*/
      padding: 25px 30px  40px;

      /* 边框设置 + 连写*/
      border-style:dotted solid double dashed;
      border-width: 10px;
      border-color: red;
      /* border: 1px solid red; */

      /* 使用属性:box-sizing = border-box 来创建一个怪异盒模型 怪异盒子模型的width和height包括border和padding的宽度 */
      box-sizing: border-box;
      /* 而box-sizing = context-box是标准盒模型。怪异盒模型中不会计算宽高边框内边距,他会自动调节内容元素的大小以保持整体性*/
      /* box-sizing: content-box; */
    }
  </style>
</head>
  <div class="box"></div>
<body>

</body>
</html>

二.两列布局

实现方法:①.两列布局浮动 ②.定位 ③.flex布局

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>两列布局</title>
  <style>
    /* 两列布局浮动 */
    .way-main {
        width: 100%;
        height: 470px;
        min-width: 220px;
        border: 10px solid pink;
        box-sizing: border-box;
    }
    .way-main:after {
        content: "";
        display: block;
        overflow: hidden;
        clear: both;
    }
    .way-left {
        float: left;
        width: 200px;
        height: 100%;
        background-color: aqua;
    }
    .way-right {
        display: block;
        height: 100%;
        background-color: bisque;
    }
    
    /* 定位 */
    /* .way-main {
        position: relative;
        width: 100%;
        min-width: 220px;
        border: 10px solid pink;
        box-sizing: border-box;
    }
    .way-left {
        position: absolute;
        top: 0;
        left: 0;
        width: 200px;
        background-color: aqua;
    }
    .way-right {
        padding-left: 200px;
        width: 100%;
        box-sizing: border-box;
        background-color: bisque;
    } */
  
    /* display: flex; */
    .way-main {
        display: flex;
        width: 100%;
        min-width: 220px;
        border: 10px solid pink;
        box-sizing: border-box;
    }
    .way-left {
        width: 200px;
        background-color: aqua;
    }
    .way-right {
        flex: 1;
        box-sizing: border-box;
        background-color: bisque;
    }
  </style>
</head>
<body>
    <div class="way-main">
        <div class="way-left">左</div>
        <div class="way-right">右</div>
    </div>
</body>
</html>

三.三栏布局

1.三栏布局定位

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>三栏布局定位</title>
    <style>
      .container {
        border: 3px solid rgb(225, 19, 63);
        position: relative;
        height: 100vh;
      }
      .left {
        background-color: aqua;
        position: absolute;
        left: 0;
        width: 100px;
        height: 100vh;
      }
      .right {
        background-color: rgb(131, 54, 176);
        position: absolute;
        width: 100px;
        height: 100vh;
        right: 0;
      }
      .center {
        background-color: rgb(1, 34, 34);
        position: absolute;
        left: 100px;
        right: 100px;
        height: 100vh;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="center"></div>
      <div class="left"></div>
      <div class="right"></div>
    </div>
  </body>
</html>

2.三栏布局 flex

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>三栏布局display: flex;</title>
  <style>
    .box1 {
      width: 100%;
      height: 100vh;
      display: flex;
    }
    .box2 {
      /* 这里设置了一下增长起点 1,压缩起点 0 */
      flex: 1 0;
    }
  </style>
</head>
<body>
  <div class="box1">
    <div class="box2" style="background-color: aqua;"></div>
    <div class="box2" style="background-color: pink;"></div>
    <div class="box2" style="background-color: red;"></div>
  </div>
</body>
</html>

四.圣杯布局

1.圣杯布局利于BFC元素与浮动元素

圣杯布局是一种三列布局,两边定宽,中间自适应的布局。
圣杯布局的原理:
当子元素处于浮动状态时,设置负margin,子元素会覆盖到兄弟元素上利于BFC元素与浮动元素不会相互覆盖的特性实现圣杯布局。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>圣杯布局</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .left {
        float: left;
        width: 220px;
        height: 100px;
        background-color: blue;
      }
      .center {
        height: 100px;
        overflow: hidden;
        background-color: yellow;
      }
      .right {
        float: right;
        width: 220px;
        height: 100px;
        background-color: red;
      }
    </style>
  </head>

  <body>
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>
  </body>
</html>

2.圣杯布局 flex

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>display:flex;</title>
    <style>
        .box {
            height: 200px;
            background-color: aqua;
            display: flex;
            text-align: center;
        }
        .left {
            width: 200px;
            order: 1;
            background-color: burlywood;
        }
        .center {
            flex: 1;
            order: 2;
        }
        .right {
            width: 200px;
            order: 3;
            background-color: rgb(149, 32, 60);
        } 
    </style>

</head>

<body>
    <div class="box">
        <div class="center">中间</div>
        <div class="left">左侧</div>
        <div class="right">右侧</div>
    </div>
</body>

</html>

 3.圣杯布局定位

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绝对定位</title>
    <style>
         .box {
            height: 200px;
            background-color: rgb(198, 22, 238);
            position: relative;
        }
        .center {
            height: 200px;
            /* 留出左右两个位置 */
            margin: 0 200px;

        }
        .left {
            width: 200px;
            height: 200px;
            position:absolute;
            background-color: burlywood;
            left: 0;
            top: 0;
        }
        .right {
            width: 200px;
            height: 200px;
            position:absolute;
            background-color: rgb(149, 32, 60);
            right: 0;
            top: 0;
        }
    </style>

</head>

<body>
    <div class="box">
        <div class="center">中间</div>
        <div class="left">左侧</div>
        <div class="right">右侧</div>
    </div>
</body>

</html>

 五.双飞翼布局

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>双飞翼布局</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      html {
        width: 100%;
        height: 100%;
        text-align: center;
      }
      body {
        display: flex;
        width: 100%;
        height: 100%;
        flex-direction: column;
      }
      .header {
        background-color: grey;
        height: 50px;
      }
      .footer {
        background-color: grey;
        height: 50px;
      }
      .outer {
        flex: 1;
      }
      .center {
        float: left;
        width: 100%;
        background-color: darkslateblue;
        height: 100%;
      }
      .left {
        float: left;
        margin-left: -100%;
        width: 100px;
        background-color: burlywood;
        height: 100%;
      }
      .right {
        float: left;
        width: 200px;
        background-color: cyan;
        margin-left: -200px;
        height: 100%;
      }
      .content {
        margin-left: 100px;
        margin-right: 200px;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <body>
      <div class="header">header</div>
      <div class="outer">
        <div class="center">
          <div class="content">content</div>
        </div>
        <div class="left">left</div>
        <div class="right">right</div>
      </div>
      <div class="footer">footer</div>
    </body>
  </body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

camellia小凡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值