当前位置:网站首页>Flexible layout (display:flex;) Attribute details

Flexible layout (display:flex;) Attribute details

2022-06-25 14:38:00 AnnGreen

Link to the original text :https://www.cnblogs.com/hellocd/p/10443237.html

Elastic layout (display:flex;) Properties,

Flexbox  yes flexible box For short ( notes : intend “ Flexible box container ”), yes  CSS3  New layout mode introduced . It determines how elements are arranged on the page , So that they can be displayed predictably under different screen sizes and devices .

It's called Flexbox , Because it can expand and shrink flex Elements in container , To maximize the available space . Same layout as before ( Such as table Layout and floating elements, inline block elements ) comparison ,Flexbox Is a more powerful way :

  • Arrange elements in different directions
  • Rearrange the display order of elements
  • Change the alignment of elements
  • Dynamically loading elements into containers

One 、 Basic concepts

use Flex Elements of layout , be called Flex Containers (flex container), abbreviation " Containers ". All its child elements automatically become container members , be called Flex project (flex item), abbreviation " project ".

1287814-20190227105227947-1509987029.png

stay Flexbox In the model , There are three core concepts :
– flex term ( notes : Also known as flex Subelement ), Elements that need layout
– flex Containers , It contains flex term
– Arrange the direction (direction), To determine the flex The layout direction of the item

Two 、 Container attribute

1287814-20190227105554256-71254015.png

2.1  flex-direction:

  • row( The default value is ): The principal axis is horizontal , The starting point is on the left .
  • row-reverse: The principal axis is horizontal , The starting point is on the right .
  • column: The principal axis is perpendicular , The starting point is at the top .
  • column-reverse: The principal axis is perpendicular , Starting edge .

1287814-20190227112100971-1704943994.png

2.2   flex-wrap:

  • nowrap( Default ): Don't wrap .
  • wrap: Line break , The first row is at the top .
  • wrap-reverse: Line break , The first row is at the bottom .

2.3  justify-content:

  • flex-start( The default value is ): Align left
  • flex-end: Right alignment
  • center: In the middle
  • space-between: full-justified , The intervals between the items are all equal .
  • space-around: The spacing between each item is equal . therefore , The spacing between items is twice as large as the spacing between items and the border .

1287814-20190227115738642-2112201313.gif

2.4  align-items:

  • flex-start: Align the starting points of the intersecting axes .
  • flex-end: The ends of the intersecting axes are aligned .
  • center: Align the midpoint of the intersecting axis .
  • baseline: Baseline alignment of the first line of text for the project .
  • stretch( The default value is ): If the project is not set to height or set to auto, Will fill the entire container .

1287814-20190227134053190-1350217843.gif

2.5  align-content:

Defines the alignment of multiple axes , If the project has only one axis , Then this property will not work

  • flex-start: Align with the starting point of the intersecting axis .
  • flex-end: Align with the end of the cross axis .
  • center: Align with the midpoint of the intersecting axis .
  • space-between: Align with both ends of the cross axis , The average distribution of spacing between axes .
  • space-around: The spacing between each axis is equal . therefore , The spacing between the axes is twice as large as the spacing between the axes and the borders .
  • stretch( The default value is ): The axis occupies the entire cross axis .
    1287814-20190227134814322-88632295.png

combination  justify-content and align-items, Look at the  flex-direction  Under the action of two different attribute values , What's the difference :

1287814-20190227134239511-1709887438.gif

3、 ... and 、 Item attribute

1287814-20190227135037726-1170549985.png

3.1 order attribute

1287814-20200814180820136-1259976518.png

3.2 flex-grow attribute

flex-grow Attribute defines the magnification of the item , The default is 0, That is, if there is any remaining space , And don't zoom in .

If all of the items flex-grow Attributes are 1, Then they will divide the remaining space equally ( If any ). If a project flex-grow The attribute is 2, Everything else 1, Then the former will occupy twice as much space as the others .

1287814-20200814180912736-504097544.png

3.3 flex-shrink attribute

flex-shrink Attribute defines the reduction ratio of the project , The default is 1, That is, if there is not enough space , The project will shrink .

.item {
  flex-shrink: <number>; /* default 1 */
}

bg2015071015.jpg

If all of the items flex-shrink Attributes are 1, When space runs out , I'm going to scale it down . If a project flex-shrink The attribute is 0, Everything else 1, When there is not enough space , The former does not shrink .

Negative values are not valid for this property .

3.4 align-self attribute

align-self Property allows a single item to have a different alignment than other items , covering align-items attribute . The default value is auto, Represents the... That inherits the parent element align-items attribute , If there is no parent element , Is equivalent to stretch.

.item {
  align-self: auto | flex-start | flex-end | center | baseline | stretch;
}

1287814-20200814180755315-1277154942.png

Elastic layout does not change the width of the project by default , But it changes the height of the project by default . If the project does not explicitly specify the height , It will occupy all the height of the container .

Reference resources :http://www.ruanyifeng.com/blog/2018/10/flexbox-form.html

http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html

原网站

版权声明
本文为[AnnGreen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251427351268.html