Tips for using table to implement layouts

Source: Internet
Author: User
This time to bring the use of table to achieve the layout of the technique, the use of table to realize the layout of the considerations, the following is the actual case, together to see.

This article describes the CSS using table to implement five common layout methods examples, share to everyone, specifically as follows:

Layout one:

Effect:

Code:

Html:

<p class= "header" >header</p><p class= "main" >main</p><p class= "Footer" >footer</p >

Note: P must have content, otherwise it will not show

Css:

body{  margin:0;  padding:0;  width:100%;  MIN-HEIGHT:100VH;  display:table;  Text-align:center;}. header,.main,.footer{  Display:table-row;}. header{  height:50px;  Background:tomato;}. main{  Background:skyblue;}. footer{  height:50px;  Background: #9d70ff;}

Layout two:

Effect:

Code:

Html:

<p class= "header" >header</p><p class= "main" >  <p class= "left" >left</p>  <p class= "right" >right</p></p><p class= "Footer" >footer</p>

Css:

body{  margin:0;  padding:0;  width:100%;  MIN-HEIGHT:100VH;  display:table;  Text-align:center;}. header,.main,.footer{  Display:table-row;}. header{  height:50px;  Background:tomato;}. main{  width:100%;  display:table;  Height:calc (100vh-100px);}. Main. left{  width:300px;  Display:table-cell;  Background: #fcea96;}. Main. right{  Display:table-cell;  Background:skyblue;}. footer{  height:50px;  Background: #9d70ff;}

Note: 100px in the Height property of main is the sum of the header and footer heights

Layout three:

Effect:

Code:

Html:

<p class= "left" >left</p><p class= "right" >  <p class= "header" >header</p>  < P class= "main" >main</p>  <p class= "Footer" >footer</p></p>

Css:

body{  margin:0;  padding:0;  MIN-HEIGHT:100VH;  display:table;  Text-align:center;}. left{  Display:table-cell;  width:200px;  Background:tomato;}. right{  display:table;  Width:calc (100vw-200px);  HEIGHT:100VH;}. header,.main,.footer{  Display:table-row;}. header{  height:50px;  Background:skyblue;}. main{  background: #fcea96;}. footer{  height:50px;  Background: #9d70ff;}

Layout four (double column layout, example for left fixed, right adaptive):

Effect:

Code:

Html:

<p class= "left" >left</p><p class= "right" >right</p>

Css:

body{  margin:0;  padding:0;  width:100%;  HEIGHT:100VH;  display:table;  Text-align:center;}. left,.right{  Display:table-cell;}. left{  width:300px;  Background:tomato;}. right{  Background:skyblue;}

Layout Five (three-column layout, example for left fixed, right fixed, intermediate adaptive):

Effect:

Code:

Html:

<p class= "left" >left</p><p class= "Middle" >middle</p><p class= "right" >right</p >

Css:

body{  margin:0;  padding:0;  width:100%;  HEIGHT:100VH;  display:table;  Text-align:center;}. left,.middle,.right{  Display:table-cell;}. left{  width:300px;  Background:tomato;}. middle{  background: #ffe69e;}. right{  width:200px;  Background:skyblue;}

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Animated sequence of CSS3 animation

A detailed description of the transform function in CSS3

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.