css写布局

一:左右布局

1.用float浮动来实现左右布局:
HTML代码:

<div class="father clearfix">
<div class="son1"></div>
<div class="son2"></div>
</div>

css代码:

.clearfix::{content:''; display:block; clear:both;}
.father{width:205px;  }
.son1{float:left; width:100px; height:100px; background:black;}
.son2{float:left; width:100px; height:100px; background:green;}

演示:


01.png

2用绝对定位来实现左右布局:
HTML代码:

<div class="father ">
<div class="son1"></div>
<div class="son2"></div>
</div>

css代码:

.father{
            position: relative;
            border: 1px solid red;
            width: 205px;
}
.son1{
          position: absolute;
            left:0; 
            border: 1px solid red;
            background: black;
            width: 100px;
            height: 100px;
        }
.son2{
            position: absolute;
            right: 0;
            border: 1px solid red;
            background: green;
            width: 100px;
            height: 100px;

演示:


01.png

二:多列布局:

HTM代码:

    <!--头部  -->
    <div class="header">
        <div class="headerfl"></div>
        <div class="headerfr">
            <div class="top"></div>
            <div class="down"></div>
        </div>
    </div>
    <!-- 主体 -->
    <div class="container">
        <div class="containerfl"></div>
        <div class="containerfr">
            <div class="da">
                <div class="dafl">
                    <div class="dafl1"></div>
                    <div class="dafl2"></div>
                    <div class="dafl3"></div>
                </div>
                <div class="dafr"></div>
            </div>
            <div class="xiao"></div>
        </div>
    </div>
    <div class="footer"></div>

css代码:

.header{
            width: 1180px;
            height: 100%;
            margin: 10px auto;


        }
        .headerfl{
            width: 200px;
            height: 100px;
            background-color: red;
            float: left;
            margin-right: 20px;
        }
        .headerfr{
            width: 960px;
            height: 100px;
            float: left;
        }
        .top{
            width: 100px;
            height: 50px;
            background-color: green;
            float: right;
            margin-bottom:10px 
        }
        .down{
            width: 100%;
            height: 40px;
            background-color: green;
            float: left;
        }
        .container{
            width: 1180px;
            height: 100%;
            margin: 10px auto;
            
        }
        .containerfl{
            width: 250px;
            height: 500px;
            
            float: left;
            background-color: yellow;
        } 
        .marginerfr{
            width: 920px;
            height: 500px;
            margin-left: 20px;
            float: right;
        }
        .da{
           width: 920px;
           height: 450px;
           margin-bottom: 10px;
           float: left;
        }
        .dafl{
            width: 850px;
            height: 450px;
            margin: 0 5px;
            float: left;
        }
        .dafl1{
            width: 850px;
            height: 250px;
            background-color: blue;
            float: left;
        }
        .dafl2{
            width: 850px;
            height: 100px;
            background-color: blue;
            margin: 10px auto;
            float: left;
        }
        .dafl3{
            width: 850px;
            height: 80px;
            background-color: blue;
            float: left;
        }
        .dafr{
            width: 60px;
            min-height: 450px;
            background-color: black;
            float: left;
        }
        .xiao{
            width: 920px;
            height: 40px;
            background-color: green;
            float: left;
        }
       .footer{
        width: 1180px;
        height: 70px;
        background-color: red;
        clear: both;
        margin: 10px auto;
       }

演示:


02.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,807评论 1 92
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,741评论 1 45
  • 1. 前言 前端圈有个“梗”:在面试时,问个css的position属性能刷掉一半人,其中不乏工作四五年的同学。在...
    YjWorld阅读 4,543评论 5 15
  • 作者:匿名用户 链接:https://www.zhihu.com/question/29301917/answer...
    岚风的叶子阅读 346评论 0 0
  • 四月已经过去了一大半,2017年也已经过去了三分之一,马上就要到露肉的季节啦,之前看关于健身的文章,get了几个不...
    红豆酥酥酥阅读 693评论 1 2