首页 > Web开发 > 详细

CSS布局

时间:2019-03-08 19:58:07      阅读:277      评论:0      收藏:0      [点我收藏+]

常用布局方法

  table

  float+margin 

  inline-block

  flexbox

table 

  非常方便的布局方案,属于传统布局方案, 

  display   table  table-row  table-cell 跟表格布局相似

技术分享图片
<div class="table">
<div class="table-row">
<div class="left table-cell"></div>
<div class="right table-cell"></div>
</div>
</div>
<style>
    .left{
            background:red;
        }
        .right{
            background:blue;
        }
     .table{
            display: table;
            width:800px;
            height:100px;
        }
        .table-row{
            display: table-row;
        }
        .table-cell{
            vertical-align: center;
            display: table-cell;
        }
</style>
View Code
 
 
 
 
 
 
 

盒子模型

  content/width/height/padding/border/margin

display/position

  display  block/inline-block/inine

  position static/relative/absolue/fixed

    absolute/fixed 脱离文档流

      区别

        absolute是相对于上一个relative/absolute

        fixed是相对于屏幕

  z-index  层叠

flexbox现代布局

  弹性盒子

  盒子是并列的

  可以指定宽度

技术分享图片
<div class="container">
  <div class="flex red">1</div>
  <div class="flex blue">2</div>
  <div class="flex red">3</div>
</div>
<style><!--
.red{
  background:red;}
.blue{
  background:blue;
}
.container{
  display:flex;
  height:100px;
  width:800px;
}
.flex{
  flex:1
}
</style>
View Code
1
2
3

  flexbox在低版本浏览器不兼容 但是可以在移动端使用

foat

  元素"浮动"

  脱离文档流

  但是不脱离文本流

<style>   .container{     background:blue;     width:300px;     margin:20px;   }   .p1{     background:red;     float:left;     width:100px;     height:50px;   } </style> <div class="container">

  <span class="p1">   float </span>   <div class="p2">学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float

    学习float学习float学习float学习float学习float学习float</div> </div>

float
学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float学习float

 

CSS布局

原文:https://www.cnblogs.com/sonwrain/p/10497747.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!