CSS multi-column Layout implementation method introduction

Source: Internet
Author: User

In CSSTutorials (http://www.maiziedu.com/course/web/421-5342/), useCSSIt is very common to implement wide-spaced layouts such as multi-column pictures,WebFront-end project development will often be used in the Web page, the following three-column picture, such as the width of the space as an example to explain the implementation method. each picture block left floats, width 30%, left margin 2.5%:
100%= (2.5%+30%) + (2.5%+30%) + (2.5%+30%) +2.5%
<! DOCTYPE html>


<meta charset= "Utf-8" >
<meta name= "viewport" content= "width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0" >
<title> three-column picture equal width layout </title>
<style>
* { 
margin:0;
padding:0;
} 
img {
Display:block;
width:30%;
margin:2.5% 0 0 2.5%;
Float:left;
} 
</style>

<body>
<div>



</div>
</body>


width:30%; 30% that represents the width of the parent element.
height:30%: If the height of the parent element is not set, the height is not effective.

to implement a responsive square, you can use the unit VW (Viewport Width):
. Square {
width:30%;
HEIGHT:30VW;
Background:url ("byd.jpg") no-repeat Scroll center 0 transparent;
background-size:100% 100%;
margin:2.5% 0 0 2.5%;
Float:left;
} 
However, it is important to note that both low-version IE and low-version Android/ios browsers do not support Windows (viewport) units.

or use JS according to the wide setting high, ensure compatibility:
<script src= "Jquery.js" ></script>
<script>
$ (document). Ready (function () {
$ ("img"). Height ($ ("img"). width ());
});
$ (window). Resize (function () {
$ ("img"). Height ($ ("img"). width ());
});
</script>

A percent layout can also be seen as a responsive layout.
Simple and practicalpercent Layoutis also very suitable for mobile WAP page layout:
min-width:320px;
max-width:980px;
width:100%;
overflow-x: Hidden;
margin:0 Auto;
The minimum width is 320px, the maximum width is 980px, the width is automatically adjusted between 320px and 980px, and looks fine.
in the tab, set the width attribute percentage value only, such as width= "40%", without setting the Height property, so that the picture can be scaled by its original scale.
the blocks inside the container can also be arranged in percentages, such as the 60% on the left and the 40% on the right.

CSS multi-column Layout implementation method introduction

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.