"CSS" Elastic box model

Source: Internet
Author: User

Elastic box Model Flexbox

Elastic box model is a new layout mode of C3

It is a layout that ensures that elements behave properly when the page needs to accommodate different screen sizes and device types.

The purpose of introducing the flexible box model layout is to provide a more efficient way to arrange, align, and allocate white space for child elements in a container .

Compatibility

IE11

Elastic Box Model Content

The elastic box model consists of an elastic container (Flex container) and an elastic child element (Flex Item)

Convert parent container settings Display:flex to elastic container

Introduce several common methods:

Flex-direction:

row: Horizontal left-to-right arrangement, default

row-reverse: Horizontal right-to-left arrangement (last item in front)

column: vertical arrangement

column-reverse: Reverse Portrait arrangement (last item on top)

Justify-content:

  Flex-start: start point Alignment (left justified)

  flex-end: terminating point Alignment (right-aligned)

  Center: Center Alignment

  Space-around: Around

  Space-between: justify on both sides

How to center the box horizontally vertically:

1 Using the Flex box model Display:flex + justify-content:center + align-items:center

    <style>       . box{           width:400px;           height:300px;           Display:flex; Let the box become elastic box model           justify-content:center; center           align-items:center;  Center           background-color:pink;       }               . child{           width:150px;           height:150px;           Background-color:skyblue;       }              </style>

2 using position:absolute + transform:translate

     . box{           width:400px;           height:300px;           position:relative;           Background-color:pink;       }               . child{           width:150px;           height:150px;           Background-color:skyblue;           Position:absolute;            50%;            50%;           Transform:translate (-50%,-50%)       }             </style>

"CSS" Elastic box model

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.