CSS3 the use of streaming layouts (such as scaling layouts, using percentages to set width)

Source: Internet
Author: User

1, equal-ratio scaling layout

Creating a scaling layout is a way to divide a page into columns and then set their widths in proportions rather than pixels. Take the following two column layouts for example:

<!doctype html>
<meta charset= "UTF-8" >
<title>111cn.net</title>
<style>
* {
margin:0px;
padding:0px;
}

. leftcolumn {
width:33.3%;
Float:left;
Background-color:yellow;
height:300px;
}

. rightcolumn {
width:66.7%;
Float:left;
Background-color: #7FFF9B;
height:300px;
}
</style>
<body>
<div class= "Leftcolumn" >
Left
</div>
<div class= "Rightcolumn" >
Right
</div>
</body>


2, the width of the outer margin set

When using a streaming layout, in addition to the column width to use the percentage setting, the outer margin must also use a percentage (cannot use fixed pixel values) to ensure the column width + margin =100%.

The following is a 2% margin added to the left, right, and between columns:

. leftcolumn {
width:31.3%;
margin-left:2%;
margin-right:2%;
Float:left;
Background-color:yellow;
height:300px;
}

. rightcolumn {
width:62.7%;
margin-right:2%;
Float:left;
Background-color: #7FFF9B;
height:300px;
}

3, the setting of the border

Because the border is added to the perimeter of the element, and the border width does not accept a percentage value, setting a fixed-width border directly on the bar destroys the flow layout.

The solution is to add an additional <div> element to the zoom bar, and set the border to the <div> element.

<!doctype html>
<meta charset= "UTF-8" >
<title>111cn.net</title>
<style>
* {
margin:0px;
padding:0px;
}

body{
Background-color: #EFEFEF;
}

. leftcolumn {
width:31.3%;
margin-left:2%;
margin-right:2%;
Float:left;
Background-color:yellow;
}

. rightcolumn {
width:62.7%;
margin-right:2%;
Float:left;
Background-color: #7FFF9B;
}

. colomncontent {
border:1px solid Gray;
height:130px;
}
</style>
<body>
<div class= "Leftcolumn" >
<div class= "Colomncontent" >
Left
</div>
</div>
<div class= "Rightcolumn" >
<div class= "Colomncontent" >
Right
</div>
</div>
</body>

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.