HTML5 Mobile Development Flexbox layout explanation and use skill

Source: Internet
Author: User

now let's introduce the Flexbox layout syntax and use it in detail. You may be very concerned about the following issues:

1. What is the Flexbox layout?

2. What are the main scenarios for flexbox layouts?

3. Flexbox layout What is its syntax?

4. How do I actually use the Flexbox layout?

5. Flexbox layout What is its flaw?

Here are the five questions for you to analyze and analyze. I hope to give some help to those who want to try Flexbox. In the right place to use the appropriate layout method, if there is not in place, I hope you correct, together with progress.

1. What is the Flexbox layout?

1.1 Interpretation

The Flexbox layout (flexible box) module, officially known as the CSS elastic box layout, is a new layout pattern defined in CSS3.

1.2 Specific explanations

The Flexbox layout (flexible box) module, officially known as the CSS elastic box layout, is a new layout pattern defined in CSS3.

Flexbox can control the alignment, arrangement, and sort order of child elements within a container, even if the dimensions of its child elements are unknown or dynamic.

The main feature of an elastic container is the ability to adjust the width or height of its sub-elements so that it can fill the available space in the best way possible at different resolutions of the screen.

1.3 Core Ideas

Containers with flex properties and items within a container have the ability to flex calculations so that they conform to predetermined rules.

A Flex elastic box allows child elements to fill the free space or shrink to prevent child elements from exceeding the area.

2. What are the main scenarios for flexbox layouts?

1. Mostly used in mobile web-making

2.react native hybrid development layout is also based on Flexbox layout

3. Angular and other frame layouts also use flexbox layout

2.1 Specific performance

1 Arrange the elements in a horizontal position without setting the specific width of the element, and fold the rows when there is not enough space in the row.

2 quickly arrange the elements into vertical rows.

3 aligns the elements along the left, right, or middle, or both sides of the parent container (before using text-align:justify only, and many compatibility for the low-version browser).

4 Change the order in which the elements are displayed without changing the HTML code.

5 Set the space occupied by each element to a ratio of the parent element's width/height, without worrying about the layout being broken when the parent element's size is set to a percentage value or when the size of the window changes.

6 implements the horizontal, vertical center of the element.

With this effect, let's take a look at how each effect is implemented using the Flexbox layout.

3. Flexbox layout What is its syntax?

3.1 Refer to others summary, first look at the basic concept of Flexbox

Elements that use flex layouts, called Flex container, are referred to as "containers." All of its child elements automatically become container members, known as Flex items (Flex Item), or "project" for short.

The container has two axes by default:

1. The horizontal spindle (main axis) and the vertical intersection axis (cross axis).

2. The starting position of the spindle (the intersection with the border) is called main start. The end position is called main end;

3. The starting position of the crossover axis is called Cross start, and the end position is called the crossing end.

4. The project is arranged by default along the spindle. The main axis space occupied by a single item is called the main size, and the occupied intersection space is called cross size.

3.2 Concrete Layout

Any element can be specified as a flex layout, let's look at how to write.

Write a few labels

Set style

Note: When set to flex layout, the float, clear, and vertical-align properties of child elements are invalidated.

3.2 Container Properties

Let's take a look at the properties of the container that others have summed up and share it with you now.


? 1. Flex-direction

Meaning: The Flex-direction property determines the direction of the spindle (that is, the direction of the project)
Syntax: Flex-direction:row | Row-reverse | Column | Column-reverse;


Explanation:

Row (default): The spindle is horizontal and the starting point is on the left side.

Row-reverse: The spindle is in the horizontal direction, starting at the right end.

Column: The spindle is in the vertical direction, starting at the top edge.

Column-reverse: The spindle is in the vertical direction, starting at the bottom edge.


Realize:


? 2. Flex-wrap Meaning:

By default, items are lined up in a line (also known as the "axis"). The Flex-wrap property defines how to wrap a line if one of the axes does not fit.


Grammar:

Meaning
    1. NoWrap (default): No Line break.

    2. Wrap: Wrap, the first line is above.

    3. Wrap-reverse: Line break, the first line is below

Implementation: Tags

? 1. NoWrap (default): Does not break the line.

Style settings

effect

? 2. Wrap: Wrap, the first line is above.

Style settings

effect


? 3. Wrap-reverse: Line break, the first line is below

Style settings


    Effect

    ? 4. Flex-flow

    Meaning:

    The Flex-flow property is a shorthand for the Flex-direction property and Flex-wrap property, and the default value is row nowrap.


    Grammar

    Flex-flow: | |;


    Specific implementation


    Effect


    ?5. Justify-content Meaning:

    The Justify-content property defines how the item is aligned on the spindle.


    Grammar

    parameter Interpretation

      1. Flex-start (default): Left Justified

      2. Flex-end: Right-justified

      3. Center: Center

      4. Space-between: Justified, the interval between items is equal.

      5. Space-around: The intervals on each side of the item are equal. Therefore, the interval between items is one times larger than the interval between items and borders.


    1. Flex-start (default): left-aligned concrete style

    Effect Show

    2. Flex-end: Right-justified

    Specific style

    Effect Show

    3. Center: center-specific style

    Effect Show


    ? 6. Space-between: Justified, the interval between items is equal.

    Specific style


    Effect Show

    ? 7. Space-around: The intervals on each side of the item are equal. Therefore, the interval between items is one times larger than the interval between items and borders.

    Specific style

    Effect Show

    ? 8. Align-items

    Meaning

    The Align-items property defines how the item is aligned on the intersection axis.

    Grammar:

    Parameter interpretation


      1. Flex-start: The start alignment of the intersection axis.

      2. Flex-end: The end alignment of the intersection axis.

      3. Center: The midpoint alignment of the intersection axis.

      4. Baseline: The baseline alignment of the first line of text for the item.

      5. Stretch (default): If the item is not set to height or auto, it fills the height of the entire container.


    Specific style

    Effect Show

    (Note: The rest of the style everyone to try)


    9. Align-content meaning

    The Align-content attribute defines the alignment of multiple axes. If the item has only one axis, this property does not work.


    Grammar

    Parameter interpretation
      1. Flex-start: Aligns with the starting point of the intersection axis.

      2. Flex-end: Aligns with the end of the intersection axis.

      3. Center: Aligns with the midpoint of the intersection axis.

      4. Space-between: aligned with the intersection axis and evenly spaced between the axes.

      5. Space-around: The intervals between each axis are equal. Therefore, the spacing between the axes is greater than the spacing between the axes and the borders.


    (Note: The rest of the style everyone to try)

    For more information on HTML5 tutorials, please feel free to follow the rookie online.

    HTML5 Mobile Development Flexbox layout explanation and use skill

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.