关于布局的思考总结

实现一列布局

HTML:
<body>
<!-- 单列布局 -->
<div class="top"></div>
<div class="main"></div>
<div class="footer"></div>
</body>

CSS:
.top{
    height:100px;
    background:#7FF;
}
.main{
    width: 800px;
    height: 300px;
    background:#2dd;
    margin: 0 auto;
}
.footer{
    width: 800px;
    height: 100px;
    background: #900;
    margin: 0 auto;
}

效果图:

oneColumn.png

实现两列自适应布局

HTML:
<body>
<!-- 两列自适应 -->
<div class="left"></div>
<div class="right"></div>
</body>

CSS:
.left{
    width: 20%;
    height: 500px;
    float: left;
    background: #3aa;
}
.right{
    width: 80%;
    height: 500px;
    float: right;
    background: #900;
}

效果图:


twoColumnAdaptive.png

固定宽度两列布局

HTML:
 <body>
<!-- 固定宽度两列布局 -->
<div class="main">
<div class="left"></div>
<div class="right"></div>
</div>
</body>

CSS:
.main{
    width: 800px;
    margin: 0 auto;
}
.left{
    width:220px;
    height: 500px;
    float: left;
    background: #3aa;
}
.right{
    width:580px;
    height: 500px;
    float: right;
    background: #900;
}

效果图:

columnTwoFixed01.png

三列自适应布局

HTML:
<body>
<!--三列布局 -->
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</body>

CSS:
.left{
    width: 33.33%;
    height:500px;
    float: left;
    background:#7FF;
}
.middle{
    width: 33.33%;
    height:500px;
    float: left;
    background:#2dd;
}
.right{
    width: 33.33%;
    height:500px;
    float: right;
    background: #900;
}

效果图:

threeColumn.png

三列布局之左右固定中间自适应

HTML:
<body>
<!--三列布局固定宽度 -->
<div class="left">200px</div>
<div class="middle">左右固定中间自适应;左右固定中间自适应;左右固定中间自适应;左右固定中间自适应;左右固定中间自适应;左右固定中间自适应;左右固定中间自适应;左右固定中间自适应;中间自适应;中间自适应;中间自适应;中间自适应;中间自适应;中间自适应;中间自适应;中间自适应;</div>
<div class="right">300px</div>
</body>

CSS:
.left{
    width: 200px;
    height:500px;
    background:#7FF;
    position: absolute;
    left: 0;
    top:0;
}
.middle{
    height:500px;
    background:#ddd;
    margin: 0 300px 0 200px;
}
.right{
    width:300px;
    height:500px;
    background: #9dd;
    position: absolute;
    right: 0;
    top: 0;
}

效果图:

threeColumnFixed01.png

混合布局(一)

HTML:
<body>
<!-- 混合布局之中间分两列 -->
<div class="top"></div>
<div class="main">
    <div class="left"></div>
    <div class="right"></div>
</div>
<div class="footer"></div>
</body>

CSS:
.top{
    height:100px;
    background:#7FF;
}
.main{
    width: 800px;
    height: 400px;
    background:#2dd;
    margin: 0 auto;
}
.left{
    width: 200px;
    height: 400px;
    background: blue;
    float: left;
}
.right{
    width: 600px;
    height: 400px;
    background: yellow;
    float: right;
}
.footer{
    width: 800px;
    height: 100px;
    background: #900;
    margin: 0 auto;
}

效果图:

Hybrid01.png

混合布局02

HTML:
<body>
<!-- 混合布局之02 -->
<div class="top"></div>
<div class="main">
    <div class="left"></div>
    <div class="right">
        <div class="sub_l"></div>
        <div class="sub_r"></div>
    </div>
</div>
<div class="footer"></div>
</body>

CSS:
.top{
    height:100px;
    background:#7FF;
}
.main{
    width: 800px;
    height: 400px;
    background:#2dd;
    margin: 0 auto;
}
.left{
    width: 200px;
    height: 400px;
    background: blue;
    float: left;
}
.right{
    width: 600px;
    height: 400px;
    background: yellow;
    float: right;
}
.sub_l{
    width: 400px;
    height: 400px;
    background: green;
    float: left;
}
.sub_r{
    width: 200px;
    height: 400px;
    background: purple;
    float: right;

}
.footer{
    width: 800px;
    height: 100px;
    background: #900;
    margin: 0 auto;
}

效果图:

Hybrid02.png

混合布局03

HTML:
<body>
<!-- 混合布局之03 -->
<div class="top">
    <div class="head"></div>
</div>
<div class="main">
    <div class="left"></div>
    <div class="right">
        <div class="sub_l"></div>
        <div class="sub_r"></div>
    </div>
</div>
<div class="footer"></div>
</body>

CSS:
.top {
    height: 100px;
    background: #7FF;
}

.head {
    height: 100px;
    width: 800px;
    background: pink;
    margin: 0 auto;
}

.main {
    width: 800px;
    height: 400px;
    background: #2dd;
    margin: 0 auto;
}

.left {
    width: 200px;
    height: 400px;
    background: blue;
    float: left;
}

.right {
    width: 600px;
    height: 400px;
    background: yellow;
    float: right;
}

.sub_l {
    width: 400px;
    height: 400px;
    background: green;
    float: left;
}

.sub_r {
    width: 200px;
    height: 400px;
    background: purple;
    float: right;
}

.footer {
    width: 800px;
    height: 100px;
    background: #900;
    margin: 0 auto;
}

效果图:

Hybrid03.png

需要源码的小伙伴可在我的github上查看或下载

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

推荐阅读更多精彩内容

  • 前言 温馨提示:本文较长,图片较多,本来是想写一篇 CSS 布局方式的,但是奈何 CSS 布局方式种类太多并且实现...
    sunshine小小倩阅读 3,173评论 0 59
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,805评论 1 92
  • 翻译自“Collection View Programming Guide for iOS” 0 关于iOS集合视...
    lakerszhy阅读 3,924评论 1 22
  • iOS布局体系的概览 在我的CSDN博客中的几篇文章分别介绍MyLayout布局体系中的视图从一个方向依次排列...
    欧阳大哥2013阅读 10,827评论 11 91
  • 以为是 亿万次的回眸 寻觅于华丽的邂逅 你转身望穿秋水 称爱情 可遇而不可求 以为是 化蝶纷飞的梁祝 难得生死相随...
    金钶原创阅读 244评论 0 0