Display flex arrangement in CSS (layout tool)

Display flex arrangement in CSS (layout tool)

Regarding display: flex layout, some people have a deep understanding of it, and I also learned from others' work.

display: I have no idea what flex layout is or its basic concepts, I just know how to use it. Whenever I see something like a concept, I just glance over it.

First property and usage: flex-direction

There are 4 methods I know of: row (horizontal arrangement), row-revese (horizontal reverse arrangement), column (vertical arrangement), column-reserve (vertical reverse arrangement)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div style="width:300px;border:1px solid red;display: flex;flex-direction: row;">
            <div style="width: 100px;height: 100px;background-color: black;"></div>
            <div style="width: 100px;height: 100px;background-color: green;"></div>
            <div style="width: 100px;height: 100px;background-color: yellow;"></div>
            <div style="width: 100px;height: 100px;background-color: blue;"></div>
        </div>
    </body>
</html> 

The above code and effect diagram are the effects when the attribute is row

Note: Although the width is set, the parent container is only 300px, and the child div cannot reach 100px, but adapts to the parent container

Just replace the flex-direction: row code with flex-direction: row-revese or flex-direction: column or flex-direction: column-reserve to get different effects.

Here is the effect diagram:

row-revese

-------

column

-------

column-reverse

-------

The second property and usage: flex-wrap

These are the line break properties: nowrap (no line break), wrap (line break), wrap-reverse (direction line break)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div style="width:300px;border:1px solid red;display: flex;flex-wrap: wrap;">
            <div style="width: 100px;height: 100px;background-color: black;"></div>
            <div style="width: 100px;height: 100px;background-color: green;"></div>
            <div style="width: 100px;height: 100px;background-color: yellow;"></div>
            <div style="width: 100px;height: 100px;background-color: blue;"></div>
        </div>
    </body>
</html> 

This is the code and effect diagram of the line break

-------

Replace the property flex-wrap: wrap with nowrap (no line break) and wrap-reverse (direction line break) to get the following effect:

nowrap

-----

wrap-reverse

---------

The third attribute and usage: justify-content

Contains properties: justify-content: start | end | flex-start | flex-end | center | left | right | space-between | space-around | space-evenly | stretch | safe | unsafe | baseline | first baseline | last baseline

(這些屬性都是抄別人的)

flex-start (default): left-aligned;

Align Left

flex-end: right alignment

Right Align

center: centered;

Center alignment space-between: Align both ends, with equal spacing between items;

Alignment space-around: The spacing on both sides of each item is equal, that is, the spacing between items is twice as large as the spacing between items and borders.

The distance between the two sides is equal. I, Xiaobai, also stole a lot of things from there.

Summarize

The above is the editor’s introduction to display flex organization (layout tool) in CSS. I hope it will be helpful to you!

<<:  Steps for packaging and configuring SVG components in Vue projects

>>:  Incomplete solution for using input type=text value=str

Recommend

This article teaches you how to play with CSS combination selectors

CSS combination selectors include various combina...

Example analysis of the use of GROUP_CONCAT in MySQL

This article uses an example to describe how to u...

Examples of using the Li tag in HTML

I hope to align the title on the left and the dat...

JavaScript explains the encapsulation and use of slow-motion animation

Implementing process analysis (1) How to call rep...

How to change the website accessed by http to https in nginx

Table of contents 1. Background 2. Prerequisites ...

5 solutions to CSS box collapse

First, what is box collapse? Elements that should...

6 inheritance methods of JS advanced ES6

Table of contents 1. Prototype chain inheritance ...

Tutorial on installing mysql under centos7

Recently, I plan to deploy a cloud disk on my hom...

Three common uses of openlayers6 map overlay (popup window marker text)

Table of contents 1. Write in front 2. Overlay to...

MySQL index usage instructions (single-column index and multi-column index)

1. Single column index Choosing which columns to ...

Pure js to achieve typewriter effect

This article example shares the specific code of ...

Implementation of Docker Compose multi-container deployment

Table of contents 1. WordPress deployment 1. Prep...

Example of pre-rendering method for Vue single page application

Table of contents Preface vue-cli 2.0 version vue...

How to install Nginx in a specified location in Centos system

How to install Nginx in a specified location in C...