flex布局常见效果

1、俩端对齐,项目之间的间距都相等

 // html
<div class="container">
    <div></div>
    <div></div>
    <div></div>
</div>

// css
.container{
    width: 500px;
    background-color: bisque;
    display: flex;
    justify-content: space-between; 

}
.container div{
    width: 100px;
    height: 100px;
    background-color: skyblue;
}

效果:


2、一侧固定宽度,另一侧随屏幕变化而变化

// html
<div class="container">
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</div>

// css
.container{
    width: 500px;
    background-color: bisque;
    display: flex;
}
.box1,.box2{
    width: 100px;
    height: 100px;
    background-color: skyblue;
}
.box2{
    background-color: pink;
}
.box3{
    background-color: yellowgreen;
    flex-grow: 1;
}

效果:


3、子元素在一行排列,平分父元素宽度

// html
<div class="container">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

// css
.container{
    width: 500px;
    background-color: bisque;
    display: flex;
    flex-wrap: nowrap;
}
.container > div{
    width: 100px;
    height: 100px;
    margin:0 10px;
    background-color: skyblue;
}

效果:


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

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AGI阅读 16,018评论 3 119
  • 2018.06.21 星期四 深圳 今天去了两个地方,一个是朋友推荐中医瘦身,我现在急着想瘦下来; 一个去了壹壹互...
    油漆女王胡婷婷阅读 193评论 0 0
  • 截至7月16日,质管中心共分析安全气500来个,较前日增长200个,cod
    成品曹红霞阅读 151评论 0 0