Home Web Front-end CSS Tutorial Detailed graphic explanation of how to use the CSS align-content property

Detailed graphic explanation of how to use the CSS align-content property

Sep 14, 2018 pm 01:46 PM

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 know how 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:

<div class="box">
    <div style="background-color:red;"></div>
     <div style="background-color:orange;"></div>
     <div style="background-color:yellow;"></div>
     <div style="background-color:green;"></div>
  </div>
Copy after login

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;
  }
Copy after login

Rendering:

Detailed graphic explanation of how to use the CSS align-content property

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does placeholder mean in vue What does placeholder mean in vue May 07, 2024 am 09:57 AM

What does placeholder mean in vue

How to write spaces in vue How to write spaces in vue Apr 30, 2024 am 05:42 AM

How to write spaces in vue

What does span mean in js What does span mean in js May 06, 2024 am 11:42 AM

What does span mean in js

How to get dom in vue How to get dom in vue Apr 30, 2024 am 05:36 AM

How to get dom in vue

What does rem mean in js What does rem mean in js May 06, 2024 am 11:30 AM

What does rem mean in js

How to introduce images into vue How to introduce images into vue May 02, 2024 pm 10:48 PM

How to introduce images into vue

What is the function of span tag What is the function of span tag Apr 30, 2024 pm 01:54 PM

What is the function of span tag

What language is the browser plug-in written in? What language is the browser plug-in written in? May 08, 2024 pm 09:36 PM

What language is the browser plug-in written in?

See all articles