国学经典,永久流传《诗经朗诵全集》
《诗经朗诵全集》带你领略国学经典,永久咏传。...
2023-07-31
我是小渔歌,点击右上方“关注”,每天为你分享【前端技术知识】干货。
大家在做移动端的时候,还有人在用浮动(float)布局吗?
弹性盒模型(flex)可以解决一切,当你用熟悉了之后,你绝对不会再用浮动布局了。
下面就给大家介绍一下,这个弹性盒模型他究竟有何魅力?
演示代码公共dom结构与样式。
<style> .container { display: flex; flex-direction: row; width: 340px; border: 1px solid #000000; height: 80px; } .item { width: 40px; height: 40px; border-radius: 5px; border: 1px solid #000000; } </style> <div class="container"> <div class="item one"> 1 </div> <div class="item two"> 2 </div> <div class="item three"> 3 </div> <div class="item fourt"> 4 </div> </div>
1. flex-direction
指定弹性子元素在容器中的排列方向。
row 横向排列,左对齐。flex-direction: row
row-reverse:横向排列,右对齐,并且内容是反向顺序。flex-direction:row-reverse
column 纵向排列,顶部对齐。flex-direction:column
column-reverse 纵向排列,底部对齐,并且内容是反向顺序。flex-direction:column-reverse
2. justify-content:横轴上的对齐方式
flex-start:左对齐(默认值)。justify-content:flex-start
flex-end:右对齐。justify-content:flex-end
center:水平居中。justify-content:center
space-between:平均分布。两头没有间隙。
justify-content:space-between
space-around:平均分布。两头有间隙。
justify-content:space-around
3. align-items:纵轴上的对齐方式
这个给每个子元素设置不同的高度效果更明显一点。
flex-start:顶部对齐(默认值)。align-items:flex-start
flex-end:底部对齐。align-items:flex-end
center:居中。align-items:center
baseline:基线对齐。给第二个元素设置一个值,可以看到它是基于文字一条线对齐的。
align-items:baseline
stretch。与baseline不同的是他是基于子元素顶部一条线对象的。
align-items:stretch
4.flex-wrap:子元素换行方式
nowrap:默认单行。这时候我们不管把子元素设置多大都不会换行。
flex-wrap:nowrap
wrap:多行。flex-wrap:wrap
wrap-reverse:翻转多行。flex-wrap:wrap-reverse
initial。inherit:继承。5.align-content:用于修改flex-wrap属性,修改各行对齐方式
flex-start。align-content:flex-start
flex-end。align-content:flex-end
center。align-content:center
space-between。align-content:space-between
space-around。align-content:space-around
stretch:默认。上面是父元素的属性,再来看下弹性子元素的属性有哪些?
order 属性值为整数,数字越小,越靠前。把第四个元素设置成-1。
order:-1
align-self:纵轴。单独设置某一个子元素的排列方式,这里我们给第四个元素再设置成center,这个大家可以试试其它值,同align-items属性值。
align-self:center
flex:用于指定弹性子元素之间怎么分配空间。设置元素的占用空间,这里我们给第四个元素设置成2,可以看到它比其它元素占用的空间要大。
flex:2
大家可以动手试下啦[中国赞]
往期精彩内容
能用CSS实现的效果,就尽量把Javascript踢开吧?
在JavaScript中call与apply的实际应用你知道多少?
以上内容就是为大家推荐的float(你还在傻傻地用float吗)最佳回答,如果还想搜索其他问题,请收藏本网站或点击搜索更多问题
内容来源于网络仅供参考版权声明:所有来源标注为小樱知识网www.cnfyy.com的内容版权均为本站所有,若您需要引用、转载,只需要注明来源及原文链接即可。
本文标题:float(你还在傻傻地用float吗)
本文地址:https://www.cnfyy.com/shcs/801331.html
相关文章
热点文章
2021年独生子女补贴新政策是真的吗(独生子女证有有效期吗)
2021年国庆节阅兵仪式几点开始几点结束(2021年国庆节还有阅兵吗)
鼠目寸光一点红是什么生肖动物(鼠目寸光一点红)指什么生肖,紧密
k0到k9的玩法大全(强制gc的玩法和注意事项)
入土为安是什么生肖《入土为安》打一个生肖动物,词语解释
浙江12月底全面停工是真的吗(浙江什么时候放假停工)
如何做t(t怎么把p做哭)
北京口碑最差的三甲医院(北京301医院最擅长什么)