This time I will bring you a detailed explanation of the layout of the display attribute in CSS3. What are the precautions for the layout of the display attribute in CSS3? The following is a practical case, let's take a look.
Recently I am learning WeChat applet. When designing the layout of the homepage, I came across a new layout method display:flex.container { display: flex; flex-direction: column; align-items: center; background-color: #b3d4db; }
vertical-align attributes of child elements will be invalid.
It can be applied to containers or inline elements. (The above description is combined with the WeChat developer tool description) In 2009, W3C proposed a new solution - Flex layout, which can implement various Elements that adopt Flex layout are called Flex containers (flex containers), or "containers" for short. All its child elements automatically become container members, called Flex items (flex items), referred to as "items". The container has two axes by default: the horizontal main axis and the vertical cross axis. The starting position of the main axis (the intersection with the border) is called main start, and the ending position is called main end; the starting position of the cross axis is called cross start, and the ending position is called cross end. Items are arranged along the main axis by default. The main axis space occupied by a single item is called main size, and the cross axis space occupied by a single item is called cross size. The following 6 properties are set on the container:flex-direction
.box { 2 flex-direction: row | row-reverse | column | column-reverse; 3 }
flex-wrap
.box{ 2 flex-wrap: nowrap | wrap | wrap-reverse; 3 }
flex-flow
.box { 2 flex-flow: <flex-direction> || <flex-wrap>; 3 }
justify-content
.box { 2 justify-content: flex-start | flex-end | center | space-between | space-around; 3 }
align-items
.box { 2 align-items: flex-start | flex-end | center | baseline | stretch; 3 }
align-content
.box { 2 align-content: flex-start | flex-end | center | space-between | space-around | stretch; 3 }
order 项目的排列顺序。数值越小,排列越靠前,默认为0。
flex-grow 项目的放大比例,默认为0,即如果存在剩余空间,也不放大。
flex-shrink 项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。
flex-basis 在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,即项目的本来大小。
flex 是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。
align-self 允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch。
order
.item { order: <integer>; }
flex-grow
.item { flex-grow: <number>; /* default 0 */ }
flex-shrink
.item { flex-shrink: <number>; /* default 1 */ }
flex-basis
.item { flex-basis: <length> | auto; /* default auto */ }
flex
.item { flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ] }
align-self
.item { align-self: auto | flex-start | flex-end | center | baseline | stretch; }
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of Detailed explanation of display attribute layout in CSS3. For more information, please follow other related articles on the PHP Chinese website!