亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

學(xué)習(xí)DIV+CSS網(wǎng)頁布局之兩列布局

  發(fā)布時間:2016-03-15 09:35:48   作者:彼岸時光   我要評論
學(xué)習(xí)DIV+CSS網(wǎng)頁布局中的兩列布局,本文為大家分享的是DIV+CSS網(wǎng)頁布局教程的第二篇,感興趣的小伙伴們可以參考一下

DIV+CSS 網(wǎng)頁布局第二篇:兩列布局

1、寬度自適應(yīng)兩列布局

  兩列布局可以使用浮動來完成,左列設(shè)置左浮動,右列設(shè)置右浮動,這樣就省的再設(shè)置外邊距了。

  當(dāng)元素使用了浮動之后,會對周圍的元素造成影響,那么就需要清除浮動,通常使用兩種方法。可以給受到影響的元素設(shè)置 clear:both,即清除元素兩側(cè)的浮動,也可以設(shè)置具體清除哪一側(cè)的浮動:clear:left 或 clear:right,但必須清楚的知道到底是哪一側(cè)需要清除浮動的影響。也可以給浮動的父容器設(shè)置寬度,或者為 100%,同時設(shè)置 overflow:hidden,溢出隱藏也可以達到清除浮動的效果。

  同理,兩列寬度自適應(yīng),只需要將寬度按照百分比來設(shè)置,這樣當(dāng)瀏覽器窗口調(diào)整時,內(nèi)容會根據(jù)窗口的大小,按照百分比來自動調(diào)節(jié)內(nèi)容的大小。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>寬度自適應(yīng)兩列布局</title>  
  6. <style>  
  7. *{margin:0;padding:0;}   
  8. #herder{   
  9.     height:50px;   
  10.     background:blue;   
  11. }   
  12. .main-left{   
  13.     width:30%;   
  14.     height:800px;   
  15.     background:red;   
  16.     float:left;   
  17. }   
  18. .main-right{   
  19.     width:70%;   
  20.     height:800px;   
  21.     background:pink;   
  22.     float:right;   
  23. }   
  24. #footer{   
  25.     clear:both;   
  26.     height:50px;   
  27.     background:gray;   
  28. }   
  29. </style>  
  30. </head>  
  31. <body>  
  32. <div id="herder">頁頭</div>  
  33. <div class="main-left">左列</div>  
  34. <div class="main-right">右列</div>  
  35. <div id="footer">頁腳</div>  
  36. </body>  
  37. </html>  

2、固定寬度兩列布局

  寬度自適應(yīng)兩列布局在網(wǎng)站中一般很少使用,最常使用的是固定寬度的兩列布局。

  要實現(xiàn)固定寬度的兩列布局,也很簡單,只需要把左右兩列包裹起來,也就是給他們增加一個父容器,然后固定父容器的寬度,父容器的寬度固定了,那么這兩列就可以設(shè)置具體的像素寬度了,這樣就實現(xiàn)了固定寬度的兩列布局。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>固定寬度兩列布局</title>  
  6. <style>  
  7. *{margin:0;padding:0;}   
  8. #herder{   
  9.     height:50px;   
  10.     background:blue;   
  11. }   
  12. #main{   
  13.     width:960px;   
  14.     margin:0 auto;   
  15.     overflow:hidden;   
  16. }   
  17. #main .main-left{   
  18.     width:288px;   
  19.     height:800px;   
  20.     background:red;   
  21.     float:left;   
  22. }   
  23. #main .main-right{   
  24.     width:672px;   
  25.     height:800px;   
  26.     background:pink;   
  27.     float:right;   
  28. }   
  29. #footer{   
  30.     width:960px;   
  31.     height:50px;   
  32.     background:gray;   
  33.     margin:0 auto;   
  34. }   
  35. </style>  
  36. </head>  
  37. <body>  
  38. <div id="herder">頁頭</div>  
  39. <div id="main">  
  40.     <div class="main-left">左列</div>  
  41.     <div class="main-right">右列</div>  
  42. </div>  
  43. <div id="footer">頁腳</div>  
  44. </body>  
  45. </html>  

3、兩列居中自適應(yīng)布局

  同理,只需要給定父容器的寬度,然后讓父容器水平居中。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>兩列居中自適應(yīng)布局</title>  
  6. <style>  
  7. *{margin:0;padding:0;}   
  8. #herder{   
  9.     height:50px;   
  10.     background:blue;   
  11. }   
  12. #main{   
  13.     width:80%;   
  14.     margin:0 auto;   
  15.     overflow:hidden;   
  16. }   
  17. #main .main-left{   
  18.     width:20%;   
  19.     height:800px;   
  20.     background:red;   
  21.     float:left;   
  22. }   
  23. #main .main-right{   
  24.     width:80%;   
  25.     height:800px;   
  26.     background:pink;   
  27.     float:right;   
  28. }   
  29. #footer{   
  30.     width:80%;   
  31.     height:50px;   
  32.     background:gray;   
  33.     margin:0 auto;   
  34. }   
  35. </style>  
  36. </head>  
  37. <body>  
  38. <div id="herder">頁頭</div>  
  39. <div id="main">  
  40.     <div class="main-left">左列</div>  
  41.     <div class="main-right">右列</div>  
  42. </div>  
  43. <div id="footer">頁腳</div>  
  44. </body>  
  45. </html>  

4、固定寬度橫向兩列布局

  和單列布局相同,可以把所有塊包含在一個容器中,這樣做方便設(shè)置,但增加了無意義的代碼,固定寬度就是給定父容器的寬度,然后中間主體使用浮動。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>橫向兩列布局</title>  
  6. <style>  
  7. *{margin:0;padding:0;}   
  8. #warp{   
  9.     width:960px;   
  10.     margin:0 auto;   
  11.     margin-top:10px;   
  12. }   
  13. #herder{   
  14.     height:50px;   
  15.     background:blue;   
  16. }   
  17. #nav{   
  18.     height:30px;   
  19.     background:orange;   
  20.     margin:10px 0;   
  21. }   
  22. #main{   
  23.     width:100%;   
  24.     margin-bottom:10px;   
  25.     overflow:hidden;   
  26. }   
  27. #main .main-left{   
  28.     width:640px;   
  29.     height:200px;   
  30.     background:yellow;   
  31.     float:left;   
  32. }   
  33. #main .main-right{   
  34.     width:300px;   
  35.     height:200px;   
  36.     background:pink;   
  37.     float:right;   
  38. }   
  39. #content{   
  40.     width:100%;   
  41.     overflow:hidden;   
  42. }   
  43. #content .content-left{   
  44.     width:640px;   
  45.     height:800px;   
  46.     background:lightgreen;   
  47.     float:left;   
  48. }   
  49. #content .content-right-sup{   
  50.     width:300px;   
  51.     height:500px;   
  52.     background:lightblue;   
  53.     float:right;   
  54. }   
  55. #content .content-right-sub{   
  56.     width:300px;   
  57.     height:240px;   
  58.     background:purple;   
  59.     margin-top:20px;   
  60.     float:right;   
  61. }   
  62. #footer{   
  63.     height:50px;   
  64.     background:gray;   
  65.     margin-top:10px;   
  66. }   
  67. </style>  
  68. </head>  
  69. <body>  
  70. <div id="warp">  
  71.     <div id="herder">頁頭</div>  
  72.     <div id="nav">導(dǎo)航</div>  
  73.     <div id="main">  
  74.         <div class="main-left">左-上</div>  
  75.         <div class="main-right">右-上</div>  
  76.     </div>  
  77.     <div id="content">  
  78.         <div class="content-left">左-下</div>  
  79.         <div class="content-right-sup">右-上</div>  
  80.         <div class="content-right-sub">右-下</div>  
  81.     </div>  
  82.     <div id="footer">頁腳</div>  
  83. </div>  
  84. </body>  
  85. </html>  

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。

原文:http://www.cnblogs.com/Mtime/p/5272414.html

相關(guān)文章

最新評論