Most front-end workers should be familiar with some commonly used CSS properties, so today let’s talk about the slightly uncommon CSS properties. Do you knowhow to use the CSS align-content property? What are the attribute values of align-content?Friends who want to know, please continue to read below.
1. Definition and usage of CSS align-content attribute
Definition: The align-content attribute does not occupy all available items on the cross axis in the flexible container. of space to align items within the container (vertically).
Function: It will set the vertical arrangement of each item inside the free box.
Conditions: The attribute display:flex must be set on the parent element, and line wrapping must be set, flex-wrap:wrap so that the setting of this attribute will take effect.
Setting: This attribute affects the items in its container, so just set it on the parent element.
The value of align-content can be set as needed when using it.
stretch: Stretched to fit the container (default).
center: Located in the center of the container.
flex-start: Located at the beginning of the container.
flex-end: Located at the end of the container.
space-between: Located within a container with white space between lines.
space-around: Located in a container with white space before, between, and after each line.
Writing: align-content: stretch|center|flex-start|flex-end|space-between|space-around
2. Align-content instance analysis
Description: There are four small divs inside a div outside. In order to see the effect clearly, set different colors for it, and then add align-content: center;
to the big div. The div inside can be centered vertically in the container. The code is as follows:
HTML part:
CSS part:
.box { width: 100px; height: 300px; border: 1px solid #c3c3c3; display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; -webkit-align-content: center; align-content: center; } .box div { width: 100px; height: 50px; }
Rendering:
Summary: The picture effect is clear at a glance. After setting align-content: center to the parent element, the elements inside will be vertically centered in the container. As for other effects, I will not demonstrate them one by one here. You can try it yourself and see. Is it consistent with the conclusion? Especially beginners should practice more.
The above is the detailed content of Detailed graphic explanation of how to use the CSS align-content property. For more information, please follow other related articles on the PHP Chinese website!