Home >Web Front-end >CSS Tutorial >Detailed explanation of display attribute layout in CSS3
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; }The effect after compilation is very obvious, and the layout of the interface is also very reasonable. , looks very clear. So what is this attribute used for? Flex is the abbreviation of Flexible Box, which means "flexible layout" and is used to provide maximum flexibility for box-shaped models. After setting to Flex layout, the float, clear and
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 }The optional value range of the attribute is row (default) arranged from left to right along the horizontal main axis, row- reverse is arranged from right to left along the horizontal main axis, column is arranged from top to bottom along the vertical main axis, and column-reverse.
flex-wrap
.box{ 2 flex-wrap: nowrap | wrap | wrap-reverse; 3 }The optional value range of the attribute is nowrap (default) without wrapping, wrap wrapping (the first line is above) and wrap-reverse ( You know~)
flex-flow
.box { 2 flex-flow: <flex-direction> || <flex-wrap>; 3 }In the writing attribute, just connect the values of the above two methods with ||
justify-content
.box { 2 justify-content: flex-start | flex-end | center | space-between | space-around; 3 }The alignment of the item on the main axis (which axis the main axis is depends on the setting of the property flex-direction)flex-start: in Arrange from left or top on the main axisflex-end: Arrange from right or bottom on the main axiscenter: Arrange in the center on the main axisspace-between: Arrange starting from the left and right ends or the upper and lower ends on the main axis space-around: The intervals on both sides of each item are equal. Therefore, the space between items is twice as large as the space between items and the border.
align-items
.box { 2 align-items: flex-start | flex-end | center | baseline | stretch; 3 }The pictures directly explain it more clearly
align-content
.box { 2 align-content: flex-start | flex-end | center | space-between | space-around | stretch; 3 }The above has introduced the properties in the container. Let’s talk about the properties of the items in the container:
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!