码迷,mamicode.com
首页 > Web开发 > 详细

CSS布局(圣杯、双飞翼、flex)

时间:2017-09-04 11:54:07      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:pos   class   doctype   isp   pad   flex   oat   pre   html   

圣杯布局(float + 负margin + padding + position)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>圣杯</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .main{
            float: left;
            width: 100%;
            height: 500px;
            background:red;
        }
        .sub{
            position: relative;
            float: left;
            left: -200px;
            width: 200px;
            height: 500px;
            margin-left: -100%;
            background:blue;
        }
        .extra{
            position: relative;
            float: left;
            right: -180px;
            width: 180px;
            height: 500px;
            margin-left: -180px;
            background:green;
        }
        .content{
            padding: 0 180px 0 200px;
        }
    </style>
  </head>
  <body>
     <!-- 圣杯布局(float + 负margin + padding + position) -->
    <div class="content">
        <div class="main"></div>
        <div class="sub"></div>
        <div class="extra"></div>
    </div>
  </body>
</html>

双飞翼布局(float + 负margin + margin)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .content{
            float: left;
            width: 100%;
            height: 500px;
            background:red;
        }
        .sub{
            float: left;
            width: 200px;
            height: 500px;
            margin-left: -100%;
            background:blue;
        }
        .extra{
            float: left;
            width: 180px;
            height: 500px;
            margin-left: -180px;
            background:green;
        }
        .main{
            margin: 0 180px 0 200px;
        }
    </style>
  </head>
  <body>
    <!--  双飞翼布局(float + 负margin + margin) -->
    <div class="content">
        <div class="main"></div>
    </div>
    <div class="sub"></div>
    <div class="extra"></div>
  </body>
</html>

flex布局

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .content{
            display: flex;
        }
        .sub{
            width: 200px;
            height: 500px;
            background:blue;
        }
        .main{
            flex:1;
            height: 500px;
            background:red;
        }
        .extra{
            width: 180px;
            height: 500px;
            background:green;
        }
    </style>
  </head>
  <body>
    <!--  flex布局 -->
    <div class="content">
        <div class="sub"></div>
        <div class="main"></div>
        <div class="extra"></div>
    </div>
  </body>
</html>

一样效果,不一样的布局。如下:

技术分享

 

CSS布局(圣杯、双飞翼、flex)

标签:pos   class   doctype   isp   pad   flex   oat   pre   html   

原文地址:http://www.cnblogs.com/zhang-wang/p/7472699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!