Flex 项目属性:flex 布局示例

flex属性:

flex属性是flex-grow, flex-shrinkflex-basis的简写,默认值为0 1 auto。后两个属性可选。

该属性有两个快捷值:auto (1 1 auto) 和 none (0 0 auto)。

下面来看看使用项目属性flex的两个示例:

一、

CSS:

1 <style>
2         body{ margin: 0;padding: 0;font-size: 20px;font-weight: 600;text-align: center;line-height: 40px; }
3         #header,#footer{ height: 80px;background-color: #aaa; }
4         #content{ width: 100%;height: 600px;display: flex; }
5         #content div:first-of-type{ width: 300px;background-color: #bbb;flex: 0 0 auto; }
6         #content div:last-of-type{ background-color: #ccc;flex: 1; }
7 </style>

HTML:

 1 <body>
 2     <div id="header">页眉</div>
 3     <div id="content">
 4         <div>左侧固定</div>
 5         <div>
 6             右侧自适应<br />
 7             左侧CSS属性:flex: 0 0 auto;<br />
 8             右侧CSS属性:flex: 1;
 9         </div>
10     </div>
11     <div id="footer">页脚</div>
12 </body>

页面:

 

二、

CSS:

 

1 <style>
2         body{ margin: 0;padding: 0;overflow-x: hidden;font-size: 20px;font-weight: 600;text-align: center;line-height: 40px;}
3         #header,#footer{ height: 80px;background: #aaa; }
4         .content{ width: 100%;height: 500px;display: flex; }
5         .content div:nth-of-type(1),.content div:nth-of-type(3){ width: 300px;flex: 0 0 auto;background-color: #bbb; }
6         .content div:nth-of-type(2){ width: 500px;flex: 1 0 auto;background-color: #ccc; }
7 </style>

HTML:

 1 <body>
 2     <div id="header">头部</div>
 3     <div class="content">
 4         <div>左侧固定</div>
 5         <div>
 6         中间自适应<br>
 7         左侧:flex: 0 0 auto;<br>
 8         中间:flex: 1 0 auto;<br>
 9         右侧:flex: 0 0 auto;<br>
10         </div>
11         <div>右侧固定</div>
12     </div>
13     <div id="footer">底部</div>
14 </body>

页面:

 

代码可以直接复制到HTML页面运行,如果有不懂的地方请回顾Flex布局属性:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html

文章乃参考、转载其他博客所得,仅供自己学习作笔记使用!!!

转载于:https://www.cnblogs.com/Y1473/p/10262421.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值