DIV+CSS布局-固定式頁面面開度布局

來源:互聯網
上載者:User

標籤:距離   style   水平置中   header   技術   main   實現   1.0   pad   

  

DIV+CSS布局中主要CSS屬性介紹:

Float:

       Float屬性是DIV+CSS布局中最基本也是最常用的屬性,用於實現多列功能,我們知道<div>標籤預設一行只能顯示一個,而使用Float屬性可以實現一行顯示多個div的功能,最直接解釋方法就是能實現表格版面配置的多列功能。

Margin:

       Margin屬性用於設定兩個元素之間的距離。

Padding:

       Padding屬性用於設定一個元素的邊框與其內容的距離。

Clear:

       使用Float屬性設定一行有多個DIV後(多列),最好在下一行開始之前使用Clear屬性清楚一下浮動,否則上面的布局會影響到下面。

  簡單操作執行個體:下面使用執行個體如果做一個簡單又基本的布局,效果如:

代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns= "" > <head> <meta http-equiv= "Content-Type"  content= "text/html; charset=utf-8"  /> <title>DIV+CSS布局教程</title> <style type= "text/css" > #Container{      width:1000px;      margin: 0  auto; /*設定整個容器在瀏覽器中水平置中*/      background:#CF3; } #Header{      height:80px;      background:#093; } #logo{      padding-left:50px;      padding-top:20px;      padding-bottom:50px; } #Content{      height:600px;      /*此處對容器設定了高度,一般不建議對容器設定高度,一般使用overflow:auto;屬性設定容器根據內容自適應高度,如果不指定高度或不設定自適應高度,容器將預設為1個字元高度,容器下方的布局元素(footer)設定margin-top:屬性將無效*/      margin-top:20px;/*此處講解margin的用法,設定content與上面header元素之間的距離*/      background:#0FF;       } #Content-Left{      height:400px;      width:200px;      margin:20px;/*設定元素跟其他元素的距離為20像素*/      float:left;/*設定浮動,實現多列效果,div+Css布局中很重要的*/      background:#90C; } #Content-Main{      height:400px;      width:720px;      margin:20px;/*設定元素跟其他元素的距離為20像素*/      float:left;/*設定浮動,實現多列效果,div+Css布局中很重要的*/      background:#90C; } /*註:Content-Left和Content-Main元素是Content元素的子項目,兩個元素使用了float:left;設定成兩列,這個兩個元素的寬度和這個兩個元素設定的padding、margin的和一定不能大於父層Content元素的寬度,否則設定列將失敗*/ #Footer{      height:40px;      background:#90C;      margin-top:20px; } .Clear{      clear:both; } </style> </head>  <body> <div id= "Container" >      <div id= "Header" >          <div id= "logo" >這裡設定了padding屬性介紹一下padding的用法,padding將設定文本與邊框的距離。</div>      </div>      <div id= "Content" >          <div id= "Content-Left" >Content-Left</div>          <div id= "Content-Main" >Content-Main</div>      </div>      <div class = "Clear" ><!--如何你上面用到 float ,下面布局開始前最好清除一下。--></div>      <div id= "Footer" >Footer</div> </div> </body> </html>     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "" > <html xmlns= "" > <head> <meta http-equiv= "Content-Type"  content= "text/html; charset=utf-8"  /> <title>DIV+CSS布局流程</title> <style type= "text/css" > #Container{      width:1000px;      margin: 0  auto; /*設定整個容器在瀏覽器中水平置中*/      background:#CF3; } #Header{      height:80px;      background:#093; } #logo{      padding-left:50px;      padding-top:20px;      padding-bottom:50px; } #Content{      height:600px;      /*此處對容器設定了高度,一般不建議對容器設定高度,一般使用overflow:auto;屬性設定容器根據內容自適應高度,如果不指定高度或不設定自適應高度,容器將預設為1個字元高度,容器下方的布局元素(footer)設定margin-top:屬性將無效*/      margin-top:20px;/*此處講解margin的用法,設定content與上面header元素之間的距離*/      background:#0FF;       } #Content-Left{      height:400px;      width:200px;      margin:20px;/*設定元素跟其他元素的距離為20像素*/      float:left;/*設定浮動,實現多列效果,div+Css布局中很重要的*/      background:#90C; } #Content-Main{      height:400px;      width:720px;      margin:20px;/*設定元素跟其他元素的距離為20像素*/      float:left;/*設定浮動,實現多列效果,div+Css布局中很重要的*/      background:#90C; } /*註:Content-Left和Content-Main元素是Content元素的子項目,兩個元素使用了float:left;設定成兩列,這個兩個元素的寬度和這個兩個元素設定的padding、margin的和一定不能大於父層Content元素的寬度,否則設定列將失敗*/ #Footer{      height:40px;      background:#90C;      margin-top:20px; } .Clear{      clear:both; } </style> </head>  <body> <div id= "Container" >      <div id= "Header" >          <div id= "logo" >這裡設定了padding屬性介紹一下padding的用法,padding將設定文本與邊框的距離。</div>      </div>      <div id= "Content" >          <div id= "Content-Left" >Content-Left</div>          <div id= "Content-Main" >Content-Main</div>      </div>      <div class = "Clear" ><!--如何你上面用到 float ,下面布局開始前最好清除一下。--></div>      <div id= "Footer" >Footer</div> </div> </body> </html>註解:Container作為整個頁面的容器,控制著整個頁面在瀏覽器的位置,此處使用margin:0 auto;控制Container容器在瀏覽器中水平置中,一般固定寬度的布局都會用到這就代碼。

DIV+CSS布局-固定式頁面面開度布局

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.