How to implement multi-column layout with CSS

Source: Internet
Author: User

CSS several ways to implement multi-column layout

If the following three P are displayed on the same line

<p ><p style= "background-color:red" >1</p><p style= "Background-color:yellow" >2</p> <p style= "Background-color:blue" >3</p></p>

1:float implementing multi-column layouts

The Float property controls whether the target HTML component floats and how it floats. After the property is set, the object is treated as a block component.

The floating HTML component floats and immediately follows its previous component until it encounters a border, an inner patch, an outer patch, or another block.

        p>p{            border:1px solid black;            Float:left;            width:200px;            height:200px;            Text-align:center;        }

2:inline-block Box Model

The elements of the Inline-block box model do not occupy a single line, and the width and height are also supported.
The Inline-block box model is bottom-aligned by default, and Vertical-align:top aligns it to the top.

        p>p{            Display:inline-block;            border:1px solid black;            Text-align:center;            width:200px;            height:200px;            Vertical-align:top;        }

Inline-block the spacing between elements that are rendered horizontally, in the case of line breaks, or spaces separated. Remove the space and the gap will disappear naturally.


3:display:flex Flexible layout

Flex Flexible layouts are powerful, providing maximum flexibility for box-shaped models for complex layouts, and any container can be specified as a Flex layout.

The Flex-direction attribute determines the direction of the spindle, flex-direction:row, and is arranged horizontally in the parent container,Flex-direction:column; Represents the vertical arrangement in the parent container.

        p{            Display:flex;            Flex-direction:row;            height:200px;            width:600px;        }        p>p{            border:1px solid black;        }

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.