前端开发-常见CSS布局

css布局.jpg

常见的两列布局

float浮动布局

<div class="float-container">  
    <div class="float-left">左边</div>  
    <div class="float-right">左边div宽固定</div>  
</div>
.float-container{ width:100%;height:100px;}  
.float-container .float-left{float:left;width:100px;height:100%;background: #1ABC9C;}  
.float-container .float-right{height:100%;margin-left:100px;background: #FD482C;}  

flex布局

<div class="flex-container">  
    <div class="flex-left">左边</div>  
    <div class="flex-right">左边div宽固定</div>  
</div> 
.flex-container{ width:100%;height:100px;display:flex;display: -webkit-flex; }  
.flex-container .flex-left{width:100px;height:100px;flex:none;background: #1ABC9C;}  
.flex-container .flex-right{height:100px;background: #FD482C;flex:1;white-space:nowrap; }  

常见的三列布局

float浮动布局

<div class="float-contain">  
    <div class="left">左栏</div>
    <div class="right">右栏</div>
    <div class="middle">中间栏</div>
</div>
.float-contain{ width:100%;height:100px;}  
.float-contain .left{float:left;width:100px;height:100%;background: #1ABC9C}  
.float-contain .right{float:right;width:100px;height:100%;background: #FD482C}
.float-contain .middle{height:100%;background: yellow; margin-left: 100px;margin-right: 100px;}

position定位

<div class="pos-contain">  
    <div class="left">左栏</div>
    <div class="middle">中间栏</div>
    <div class="right">右栏</div>
</div>
.pos-contain{ width:100%;height:100px;position:relative;}  
.pos-contain .left{position: absolute;top:0;left:0;width:100px;height:100%;background: #1ABC9C}  
.pos-contain .right{position: absolute;top:0;right:0;width:100px;height:100%;background: #FD482C}
.pos-contain .middle{height:100%;background: yellow; margin-left: 100px;margin-right: 100px;}

flex布局

<div class="flex-contain">  
    <div class="left">左栏</div>
    <div class="middle">中间栏</div>
    <div class="right">右栏</div>
</div>
.flex-contain{ width:100%;height:100px;display:flex;display: -webkit-flex;}  
.flex-contain .left{width:100px;background: #1ABC9C;flex:none;} 
.flex-contain .right{width:100px;background: #FD482C;flex:none;} 
.flex-contain .middle{width: 100%;background:yellow;flex:1;}

圣杯布局

<div id="container">
    <div class="center">center</div>
    <div class="left">left</div>
    <div class="right">right</div>
</div>
#container{padding:0 210px;overflow: hidden;font-size: 30px;}
.left,.center,.right{float: left;}
.center{ width:100%;height: 50px;background: blue;}
.left{position:relative;left: -210px; width:200px;height: 100px;margin-left: -100%;background: red;}
.right{ position: relative;right: -210px;width: 200px;height: 100px;margin-left: -200px;background: green;}

双飞翼布局

<div id="container2">
     <div class="center2">
         <div class="wrap">center2</div>
     </div>
     <div class="left2">left2</div>
     <div class="right2">right2</div>
</div>
#container2{width:100%; }
.left2,.right2, .center2{ float: left;}
.center2{width:100%; }
.center2 .wrap{height: 200px;margin-left: 210px;margin-right: 210px;background: #392;}
.left2{ width:200px;height: 100px;background: red;margin-left: -100%;}
.right2{width:200px; height: 100px;background: blue;margin-left: -200px; }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,692评论 1 92
  • 前言 温馨提示:本文较长,图片较多,本来是想写一篇 CSS 布局方式的,但是奈何 CSS 布局方式种类太多并且实现...
    sunshine小小倩阅读 8,366评论 0 59
  • CSS布局 布局是CSS中一个重要部分,本文总结了CSS布局中的常用技巧,包括常用的水平居中、垂直居中方法,以及单...
    web前端学习阅读 5,534评论 1 38
  • 目录 常用居中垂直居中水平居中垂直水平居中 单列布局 双列&三列布局 常用居中 垂直居中 单行文本垂直居中 图片垂...
    听城阅读 3,265评论 1 2
  • 1、听。《婷婷唱古诗》《鹅妈妈》继续听,下午孩子翻出一本《we sing》手指谣,强烈要求我讲,还好有备过课的三篇...
    马行千里玥溢彩阅读 1,283评论 0 0

友情链接更多精彩内容