One hour to fix div+css layout-Fixed page opening layout This article explains the basics of using the div+css layout, and you'll use DIV+CSS for a simple page layout after reading this article.
Reprint please indicate: http://www.kwstu.com/ArticleView/divcss_2013929173533658
For the CSS prerequisites used in the DIV+CSS layout, see: http://www.kwstu.com/ArticleView/divcss_201442291125960
The main CSS properties in the Div+css layout are described in:
Float:
The Float property is the most basic and most commonly used property in the DIV+CSS layout for implementing multi-column functionality, and we know that the <div> tag can only display one line in the default row, whereas using the Float property allows you to display multiple div functions in a row. The most straightforward way to explain this is to implement the multi-column function of table layout.
Margin:
The margin property is used to set the distance between two elements.
Padding:
The Padding property is used to set the distance between the border of an element and its contents.
Clear:
Using the Float property to set a row with multiple div (multiple columns), it is best to use the clear property to clearly float before the next line starts, otherwise the above layout will affect the following.
Examples: Use examples below if you make a simple and basic layout, the effect is as follows:
Code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>div+css Layout Tutorials </title>
<style type= "Text/css" >
#Container {
width:1000px;
margin:0 auto;/* Set the entire container to be horizontally centered in the browser */
Background: #CF3;
}
#Header {
height:80px;
Background: #093;
}
#logo {
padding-left:50px;
padding-top:20px;
padding-bottom:50px;
}
#Content {
height:600px;
/* Here the container is set to a height, generally do not recommend to set the height of the container, generally use Overflow:auto; the property settings container adapts to the height of the content, and if you do not specify a height or do not set an adaptive height, the container defaults to 1 character Heights. Layout element under container (footer) Setting Margin-top: property will not be valid */
margin-top:20px;/* here to explain the usage of margin, set the distance between content and the above header elements * *
Background: #0FF;
}
#Content-left{
height:400px;
width:200px;
margin:20px;/* set element distance to other elements is 20 pixels */
float:left;/* set float, achieve multi-column effect, div+css the layout is very important */
Background: #90C;
}
#Content-main{
height:400px;
width:720px;
margin:20px;/* set element distance to other elements is 20 pixels */
float:left;/* set float, achieve multi-column effect, div+css the layout is very important */
Background: #90C;
}
*/* Note: The Content-left and content-main elements are child elements of the Content element, two elements use Float:left, set to two columns, the width of the two elements and the two elements set padding, Margin must not be greater than the width of the parent content element, otherwise the set column will fail.
#Footer {
height:40px;
Background: #90C;
margin-top:20px;
}
. clear{
Clear:both;
}
</style>
<body>
<div id= "Container" >
<div id= "Header" >
<div id= "logo" > here set the Padding property to describe the use of padding, padding will set the distance between the text and the border. </div>
</div>
<div id= "Content" >
<div id= "Content-left" >Content-Left</div>
<div id= "Content-main" >Content-Main</div>
</div>
<div class= "Clear" ><!--how you use float above, it's best to clear the layout before starting. --></div>
<div id= "Footer" >Footer</div>
</div>
</body>
Note: As a container for the entire page, container controls the location of the entire page in the browser, where margin:0 auto is used, the control container container is horizontally centered in the browser, and the general fixed-width layout uses this code.
This article only describes the most basic layout, in the specific development practice may encounter browser compatibility and other issues, encounter the details of the problem please Baidu to solve, the solution of more experience on the accumulation up.
DIV+CSS layout