网页布局

单列布局

应用场景:网页中有时候内容不多,单行内容的,最多只用margin居中就行

<!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>
        header {
            height: 100px;
            background: gray;
            width: 100%;
        }

        .main {
            width: 800px;
            height: 300px;
            background-color: pink;
            margin: 0 auto;
        }

        footer {
            width: 800px;
            height: 100px;
            background-color: rgb(43, 196, 183);
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <header></header>
    <div class="main">

    </div>
    <footer></footer>
</body>

</html>

效果:

双列布局

应用场景:就是网页中两并排的内容,采用左右浮动的形式,可以采用比列的形式,也可以使用一个固定宽度容器包裹,然后里面精确宽度

<style>

.left {

width: 20%;

height: 200px;

background-color: gray;

float: left;

}

.right {

width: 60%;

height: 200px;

background-color: pink;

float: right;

}

</style>

</head>

<body>

<div class="main">

<div class="left">left</div>

<div class="right">right</div>

</div>

</body>

效果:

三列布局

应用场景:1.就是三个都是固定宽度的内容,这时候可以采用三浮动的原则

                  2.中间自适应,两边固定宽度,这时候就可以使用绝对定位加margin

1.

<style>

* {

margin: 0;

padding: 0;

}

 

.con1 {

width: 300px;

height: 100px;

background-color: gray;

position: absolute;

left: 0;

top: 0;

}

 

.con2 {

margin-left: 300px;

margin-right: 300px;

background-color: blue;

height: 100px;

}

 

.con3 {

width: 300px;

height: 100px;

background-color: crimson;

position: absolute;

right: 0;

top: 0;

}

</style>

</head>

 

<body>

<div class="main">

<div class="con1">左边固定</div>

<div class="con2">中间自适应:百科全书是概要记述人类一切知识门类或某一知识门类的工具书

。百科全书在规模和内容上均超过其他类型的工具书。百科全书的主要作用是供人们查检必要的知识和事实资料,其完备性在于它几乎包容了各种工具书的成分,囊括了各方面的知识。被誉为“没有围墙的大学”。</div>

<div class="con3">右边固定</div>

</div>

</body>

2.

<style>

* {

margin: 0;

padding: 0;

}

 

.con1 {

width: 20%;

height: 100px;

background-color: gray;

float: left;

}

 

.con2 {

width: 60%;

background-color: blue;

height: 100px;

float: left;

}

 

.con3 {

width: 20%;

height: 100px;

background-color: crimson;

float: left;

}

</style>

</head>

 

<body>

<div class="main">

<div class="con1">左边固定</div>

<div class="con2">中间自适应:百科全书是概要记述人类一切知识门类或某一知识门类的工具书

。百科全书在规模和内容上均超过其他类型的工具书。百科全书的主要作用是供人们查检必要的知识和事实资料,其完备性在于它几乎包容了各种工具书的成分,囊括了各方面的知识。被誉为“没有围墙的大学”。</div>

<div class="con3">右边固定</div>

</div>

</body>

效果:

混合布局

应用场景:中间需要两排就可以使用两列布局再分。

 <style>
        * {
            margin: 0;
            padding: 0;
        }

        header {
            height: 100px;
            background-color: blue;
        }

        .main {
            width: 1000px;
            height: 600px;
            background-color: red;
            margin: 0 auto;
        }

        .sub-left {
            width: 40%;
            height: 100%;
            background-color: black;
            float: left;
        }

        .sub-right {
            width: 60%;
            height: 100%;
            background-color: orange;
            float: right;
        }

        footer {
            width: 1000px;
            height: 100px;
            background-color: gray;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <header></header>
    <div class="main">
        <div class="sub-left"></div>
        <div class="sub-right"></div>
    </div>
    <footer></footer>
</body>

效果:

圣杯布局

<!--
 * @Description: 
 1.布局样式,main包住三个并行的left,content,right
 2.main左右规定距离空开200px
 3.三个并行的分别设置宽度,content100%,left,right:200
 4.三个并行设置浮动
 4.margin-left:-100%,margin-right:-200px,这样就会盖住一部分content
 5.left,right,content设置positive相对地位,left:-200px;,right:-200px
 * @version: 
 * @Author: 朱宇
 * @Date: 2019-08-28 23:06:53
 * @LastEditTime: 2019-08-28 23:25:54
 -->
<!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>Document</title>
  <style>
    .main {
      margin: 0 300px 0 200px;
    }

    .content,
    .left,
    .right {
      height: 100px;
      float: left;
      position: relative;
    }

    .content {
      width: 100%;
      background-color: red;

    }

    .left {
      background-color: blue;
      width: 200px;
      margin-left: -100%;
      left: -200px;
    }

    .right {
      background-color: green;
      width: 300px;
      margin-left: -300px;
      right: -300px;
    }
  </style>
</head>

<body>
  <div class="main">
    <div class="content">1111</div>
    <div class="left">2222</div>
    <div class="right">3333</div>
  </div>
</body>

</html>

双飞翼布局

应用场景:设置三个板块,左中右三个,这三个板块加载中间的,左右两边200px宽,中间自适应

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .con {
            width: 100%;
            float: left;
        }
        .mid {
            background-color: crimson;
            margin-left: 200px;
            margin-right: 200px;
        }

        .left {
            background-color: blue;
            width: 200px;
            float: left;
            margin-left: -100%;
        }

        .right {
            background-color: pink;
            width: 200px;
            float: left;
            margin-left: -200px;
        }
    </style>
</head>

<body>
    <div class="main">
        <div class="con">
            <div class="mid">中间</div>
        </div>
        <div class="left">左边</div>
        <div class="right">右边</div>
    </div>
</body>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值