Several ways to adjust the layout of a page

Source: Internet
Author: User
1. Using floating layouts
Pros: Compatibility is better.
Cons: After floating, the element is out of the document flow and needs to be handled carefully to clear the floating and floating elements and the relationship between the surrounding elements

<! DOCTYPE html>

Note: The most important thing to note is that the middle column must be placed in the left and right two columns behind!!!

2. Using an absolute positioning layout
Advantage: The layout is relatively fast
disadvantage: The positioned element is out of the document flow, meaning its child elements are also out of the document flow, so the usability of this method is relatively poor

<! DOCTYPE html>

3. Using Flex layouts

Pros: A good solution to the disadvantages of floating and absolute positioning, now the mobile is basically a flex layout
Flex is not supported under IE8

<section class= "Layout flex" >  <style>  layout.flex left-right-center{   Display:flex;   margin-top:140px;  } . Layout.flex. left{  flex:0 0 300px;  width:300px;  background:red; }. Layout.flex. right{  flex:0 0 300px;  width:300px;  Background:blue; }. Layout.flex. center{  flex:1;  Background:yellow; } </style>  <article class= "Left-right-center" >   <p class= "left" ></p>   <p class= "center" >    

Note: The middle column should be placed in the middle!!!

4. Using the table layout
Pros: Compatibility is good
Disadvantage: One column content height increases, the other two columns of height will also increase, sometimes we do not need them to increase at the same time, not conducive to search engine crawling information;

<!--table Layout solution--><section class= "layout table" ><style>.layout.table. left-right-center{width:100% ;d isplay:table;height:100px;}. Layout.table. left{display:table-cell;width:300px;background:red;}. Layout.table. Right{display:table-cell;width:300px;background:blue;}. Layout.table. Center{display:table-cell;background:yellow;} </style><article class= "Left-right-center" ><p class= "left" ></p><p class= "center" > 

5. Grid Layout

<!--Grid Layout solution--><section class= "Layout grid" ><style>.layout.grid. left-right-center{width:100%; display:grid;grid-template-rows:100px;grid-template-columns:300px auto 300px;}. Layout.grid. left{background:red;}. Layout.grid. Right{background:blue;}. Layout.grid. Center{background:yellow;} </style><article class= "Left-right-center" ><p class= "left" ></p><p class= "center" > 

If the height is known to be removed or the height exceeds
1.flex layout height can be adaptive
2. Table layout Audou can be adaptive
3. Floating, absolute positioning, grid layout can not be adaptive height

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.