DIV+CSS佈局(進階篇)

   學習前端必不可少的就是學習HTML語言以及CSS樣式的佈局,這也通常是新手入門的攔路虎,結合上次的入門篇的兩種佈局樣式,又寫了兩個變化的樣式。基礎樣式都是有DIV+CSS樣式進行不斷的變化出來的,熟練後可以變化出其他的想要的樣式佈局。

DIV+CSS佈局

第一種佈局樣式:css三行三列布局

代碼如下:

<!DOCTYPE html>
<html>
<head>
	<title>css三行三列布局</title>
	<style type="text/css">
     *{margin: 0;
       padding: 0;
     }
     #container{
     	margin: 0 auto;
     	width: 1000px;
     	height: 600px;	
     }
     #header{
        height: 100px;
        background-color: #fc9;
        margin-bottom: 5px;
     }
     #main{
     	width: 1000px;
     	height: 500px;
     	margin-bottom: 5px;
     }
     .aside{
     	float: left;
     	width: 150px;
     	height: 500px;
     }
     #aside1{
     	/*float: left;
     	width: 150px;
     	height: 500px;*/
     	background-color: #fc9;
     	margin-right: 5px;
     }

     #content{
     	float: left;
     	width: 690px;
     	height: 500px;
     	background-color: #ccc;
     }
     #aside2{
     	/*float: left;
     	width: 150px;
     	height: 500px;*/
     	background-color: #fc9;
     	margin-left: 5px;
     }
     #botton{
     	height: 90px;
     	background-color: #ccc;
     }
	</style>
</head>
<body>
    <div id="container">
    	<div id="header"></div>
    	<div id="main">
    		<div id="aside1" class="aside"></div>
    		<div id="content"></div>
    		<div id="aside2" class="aside"></div>
    	</div>
    	<div id="botton"></div>
    </div>
</body>
</html>

三行三列式佈局效果圖如下:

第二種佈局樣式:css四行三列布局

代碼如下:

<!DOCTYPE html>
<html>
<head>
	<title>css四行三列布局</title>
	<style type="text/css">
     *{margin: 0;
       padding: 0;
     }
     #container{
     	margin: 0 auto;
     	width: 1000px;
     	height: 600px;	
     }
     #header{/*頭部*/
        height: 100px;
        background-color: #fc9;
        margin-bottom: 5px;
     }
     #nav{/*導航欄*/
     	height: 30px;
     	background-color: rgb(0,0,255);
     	margin-bottom: 5px;
     }
     #main{/*主體*/
     	width: 1000px;
     	height: 500px;
     	margin-bottom: 5px;
     }
     .aside{        
     	/*這部使用class屬性設置相同的屬性,aside1,2中只需要設置不同的屬性即可*/
     	float: left;
     	width: 150px;
     	height: 500px;
     }
     #aside1{/*若不使用class屬性同時設置相同屬性可在每個id中單獨設置*/
     	/*float: left;
     	width: 150px;
     	height: 500px;*/
     	background-color: #fc9;
     	margin-right: 5px;
     }

     #content{
     	float: left;
     	width: 690px;
     	height: 500px;
     	background-color: #ccc;
     }
     #aside2{/*若不使用class屬性同時設置相同屬性可在每個id中單獨設置*/
     	/*float: left;
     	width: 150px;
     	height: 500px;*/
     	background-color: #fc9;
     	margin-left: 5px;
     }
     #botton{/*尾部*/
     	height: 60px;
     	background-color: #ccc;
     }
	</style>
</head>
<body>
    <div id="container">
    	<div id="header"></div>
    	<div id="nav"></div>
    	<div id="main">
    		<div id="aside1" class="aside"></div>
    		<div id="content"></div>
    		<div id="aside2" class="aside"></div>
    	</div>
    	<div id="botton"></div>
    </div>
</body>
</html>

四行三列式佈局較上一個多了導航欄:

佈局樣式效果圖如下:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章