DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> CSS入門知識 >> CSS詳解 >> 使用DIV解決固定寬度布局問題(2)
使用DIV解決固定寬度布局問題(2)
編輯:CSS詳解     

下面的XHtml標記生成圖A所示的頁面。(出於簡單考慮,內容被截短。)

  1. <body>
  2. <DIVidDIVid="head">
  3. <h1>header</h1>
  4. </DIV>
  5. <DIVidDIVid="columns">
  6. <DIVidDIVid="side1">
  7. <h3>side1</h3>
  8. <ul>
  9. <li>Letmenottothemarriageoftrueminds</li>
  10. <li>Admitimpediments;loveisnotlove</li>
  11. <li>Whichalterswhenitalterationfinds</li>
  12. <li>Orbendswiththeremovertoremove</li>
  13. <li>Oh,no,itisaneverfixedmark</li>
  14. </ul>
  15. </DIV>
  16. <DIVidDIVid="content">
  17. <h2>maincontent</h2>
  18. <p>Thatlooksontempests...hisheightbetaken.</p>
  19. <p>Butbearsitout...alterationfinds.</p>
  20. <p>Whoseworth'sunknown,...theremovertoremove.</p>
  21. </DIV>
  22. <DIVidDIVid="side2">
  23. <h3>side2</h3>
  24. <ul>
  25. <li>Letmenottothemarriageoftrueminds</li>
  26. <li>Admitimpediments;loveisnotlove</li>
  27. <li>Whichalterswhenitalterationfinds</li>
  28. </ul>
  29. </DIV>
  30. </DIV>
  31. <DIVidDIVid="foot">
  32. <h3>footer</h3>
  33. <p>Orbendswith...heightbetaken.</p>
  34. </DIV>
  35. </body>

下面是將頁面設計為固定寬度布局的CSS代碼。

  1. body{
  2. font-family:Verdana,Arial,Helvetica,sans-serif;
  3. font-size:12px;
  4. margin:0px;
  5. padding:0px;
  6. }
  7. h2,h3{
  8. margin-top:0px;
  9. padding-top:0px;
  10. }
  11. DIV#head{
  12. position:absolute;
  13. width:750px;
  14. height:100px;
  15. left:0px;
  16. top:0px;
  17. background-color:#FFFF66;
  18. }
  19. DIV#columns{
  20. position:relative;
  21. width:750px;
  22. top:100px;
  23. background-color:#CCCCCC;
  24. }
  25. DIV#side1{
  26. position:absolute;
  27. width:150px;
  28. top:0px;
  29. left:0px;
  30. background-color:#FF6666;
  31. }
  32. DIV#content{
  33. position:relative;
  34. width:450px;
  35. top:0px;
  36. left:150px;
  37. background-color:#999999;
  38. }
  39. DIV#side2{
  40. position:absolute;
  41. width:150px;
  42. top:0px;
  43. left:600px;
  44. background-color:#00FF66;
  45. }
  46. DIV#foot{
  47. position:relative;
  48. width:750px;
  49. clear:both;
  50. margin-top:100px;
  51. background-color:#99FFFF;
  52. }

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved