最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

網(wǎng)頁布局入門教程 如何用CSS進(jìn)行網(wǎng)頁布局

  發(fā)布時間:2016-04-27 10:54:48   作者:佚名   我要評論
這篇文章主要為大家分享了網(wǎng)頁布局入門教程,如何用CSS進(jìn)行網(wǎng)頁布局,介紹了絕對定位布局、混合布局及結(jié)構(gòu)與表現(xiàn)原則,感興趣的小伙伴們可以參考一下

一、基礎(chǔ)概念

W3C標(biāo)準(zhǔn):由萬維網(wǎng)聯(lián)盟制定的一系列標(biāo)準(zhǔn):包括:
結(jié)構(gòu)化標(biāo)準(zhǔn)語言(HTML和XML);
表現(xiàn)標(biāo)準(zhǔn)語言(CSS);
行為標(biāo)準(zhǔn)語言(DOM和ECMAScript)。
  倡導(dǎo)結(jié)構(gòu),樣式,行為分離。

CSS中的定位機(jī)制:

1、標(biāo)準(zhǔn)文檔流(Normal flow):從上到下,從左到右,輸出文檔內(nèi)容,由塊級元素(從左到右撐滿頁面,獨(dú)占一行;觸碰到頁面邊緣時,會自動換行。常見塊級元素:div、lu、li、d、dt、p……)和行級元素(能在同一行內(nèi)顯示,不會改變HTML文檔結(jié)構(gòu)。常見行級元素:span、strong、img、input……)組成。
2、浮動(Floats):
3、絕對定位(Absolute positioning):

盒子模型:網(wǎng)頁布局的基石,有四部分組成:
邊框(border)、外邊距(margin)、內(nèi)邊距(padding)、盒子中的內(nèi)容(content)。如下圖:

盒子的尺寸=邊框+外邊距+內(nèi)邊距+盒子中的內(nèi)容尺寸

注:塊級元素和行級元素都是盒子模型。

盒子3D模型:

常見頁面布局及解決方案:

二、自動居中一列布局

關(guān)鍵詞:標(biāo)準(zhǔn)文檔流,塊級元素,margin屬性

自動居中一列布局需要設(shè)置margin左右值為auto,而且一定要設(shè)置寬度為一個定值。

  auto會根據(jù)瀏覽器的寬度自動地設(shè)置兩邊的外邊距

如果想讓頁面自動居中,當(dāng)設(shè)置margin屬性為auto的時候,不能再設(shè)置浮動和絕對定位屬性

代碼示例:

一列布局固定:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>一列布局</title>  
  5. <style>  
  6.     body{ margin:0; padding:0; font-size:30px}   
  7.     div{ text-align:center; font-weight:bold}   
  8.     .head, .main, .footer{ width:960px; margin:0 auto} /*margin屬性及具體的寬度*/   
  9.     .head{ height:100px; background:#ccc}   
  10.     .main{ height:600px; background:#FCC}   
  11.     .footer{ height:50px; background:#9CF}   
  12. </style>  
  13. </head>  
  14.   
  15. <body>  
  16.     <div class="head">head</div>  
  17.     <div class="main">main</div>  
  18.     <div class="footer">footer</div>  
  19. </body>  
  20. </html>  

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/yilieguding.html

一列布局自適應(yīng):

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>一列布局</title>  
  6. <style>  
  7.     body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  8.     div{ text-align:center; line-height:50px}   
  9.     .head, .main, .footer{width:80%;margin:0 auto} /*margin屬性及定寬為百分比*/   
  10.     .head{ height:100px; background:#ccc}   
  11.     .main{ height:600px; background:#FCC}   
  12.     .footer{ height:50px; background:#9CF}   
  13. </style>  
  14. </head>  
  15.   
  16. <body>  
  17.     <div class="head">head</div>  
  18.     <div class="main">main</div>  
  19.     <div class="footer">footer</div>  
  20. </body>  
  21. </html>  
  22.   

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/yiliezishiying.html

三、橫向兩列布局

浮動布局:CSS中規(guī)定的第二種定位機(jī)制;能夠?qū)崿F(xiàn)橫向多列布局;通過設(shè)置float屬性實(shí)現(xiàn)。

  float屬性:left | right | none

特點(diǎn):元素會左移,或右移,直至觸碰到容器為止。

注:設(shè)置了浮動的元素,仍舊處于文檔流中。當(dāng)元素沒用設(shè)置寬度值。若設(shè)置了浮動屬性,元素的寬度隨內(nèi)容的變化而變化。當(dāng)元素設(shè)置浮動屬性后,會對相鄰的元素產(chǎn)生影響,相鄰元素特指相鄰后面的元素。

清除浮動的方法:

  clear屬性——常用clear:both;clear:left;或者clear:right;同時設(shè)置width:100%(或固定寬度)+overflow:hidden;

橫向兩列布局是網(wǎng)頁布局最常見的方式之一

主要應(yīng)用技能:

  float屬性——使縱向排列的塊級元素,橫向排列
  margin屬性——設(shè)置兩列之間的間距

注:(1)當(dāng)父包含塊縮成一條時,用clear:both方法清除浮動無效,它一般用于緊鄰后面的元素的清除浮動。
(2)div塊的高度一般不需要設(shè)置。

代碼示例

兩列居中固定

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>二列布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .left{ width:20%; height:600px; background:#ccc; float:left}   
  9. .right{ width:80%; height:600px; background:#FCC; float:right}   
  10. </style>  
  11. </head>  
  12.   
  13. <body>  
  14.   <div class="left">left</div>  
  15.   <div class="right">right</div>  
  16. </body>  
  17. </html>  
  18.   

DEMO:http://Lovejulyer.github.io/Source_Code//Blog_demo/Codes2/liangliejuzhingguding.html

兩列居中自適應(yīng):**

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>二列布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .main{ width:80%; height:600px; margin:0 auto}   
  9. .left{ width:20%; height:600px; background:#ccc; float:left}   
  10. .right{ width:80%; height:600px; background:#FCC; float:right}   
  11. </style>  
  12. </head>  
  13.   
  14. <body>  
  15. <div class="main">  
  16.     <div class="left">left</div>  
  17.     <div class="right">right</div>  
  18. </div>  
  19. </body>  
  20. </html>  
  21.   

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/liangliejuzhongzishiyin.html

四、絕對定位布局

position屬性:

擁有三種定位方式:1、靜態(tài)定位 2、相對定位 3、絕對定位

可設(shè)置4個屬性值:

  static(靜態(tài)定位)

  relative(相對定位)——特點(diǎn):相對于自身原有為止進(jìn)行偏移;仍處于標(biāo)準(zhǔn)文檔流中;隨即擁有偏移屬性和Z-index屬性

  absolute(絕對定位)——特點(diǎn):建立以包含塊為基準(zhǔn)的定位;完全脫離了標(biāo)準(zhǔn)文檔流;隨即擁有偏移屬性和Z-index屬性

( 1)未設(shè)置偏移量:無論是否存在已定位祖先元素,都保持在元素初始位置;脫離了標(biāo)準(zhǔn)文檔流

(2)設(shè)置偏移量

偏移參考基準(zhǔn):無已定位祖先元素,以<html>為偏移參考基準(zhǔn)
有已定位祖先元素,以距離其最近的已定位祖先元素為偏移參照基準(zhǔn)

注:當(dāng)一個元素設(shè)置絕對定位,沒有設(shè)置寬度時,元素的寬度根據(jù)內(nèi)容進(jìn)行調(diào)節(jié)
  fixed(固定定位)

使用absolute實(shí)現(xiàn)橫向兩列布局——常用于一列固定寬度,另一列寬度自適應(yīng)的情況

主要應(yīng)用技能:
   relative——父元素相對定位
   absolute——自適應(yīng)寬度元素絕對定位
注意:固定寬度列的高度>自適應(yīng)寬度的列

代碼舉例:

三列自適應(yīng):

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>三列布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .left{ width:20%; height:600px; background:#ccc; position:absolute; left:0; top:0}   
  9. .main{ height:600px; margin:0 20%; background:#9CF}   
  10. .right{ height:600px; width:20%; position:absolute; top:0; right:0; background:#FCC;}   
  11. </style>  
  12. </head>  
  13.   
  14. <body>  
  15.   
  16.     <div class="left">left</div>  
  17.     <div class="main">main</div>  
  18.     <div class="right">right</div>  
  19. </body>  
  20. </html>  
  21.   

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/sanliezishiyin.html

三列左右固定:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>三列布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .left{ width:240px; height:600px; background:#ccc; position:absolute; left:0; top:0}   
  9. .main{ height:600px; margin:0 240px; background:#9CF}   
  10. .right{ height:600px; width:240px; position:absolute; top:0; right:0; background:#FCC;}   
  11. </style>  
  12. </head>  
  13.   
  14. <body>  
  15.   
  16.     <div class="left">left</div>  
  17.     <div class="main">main</div>  
  18.     <div class="right">right</div>  
  19. </body>  
  20. </html>  
  21.   

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/sanliezuoyouguding.html

五、混合布局及結(jié)構(gòu)與表現(xiàn)原則

混合布局01

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>混合布局01</title>  
  6. <style>  
  7.     body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  8.     div{ text-align:center; line-height:50px}   
  9.     .head{ height:100px;background:#9CF}   
  10.     .left{ width:20%; height:600px; background:#ccc; float:left}   
  11.     .right{ width:80%; height:600px;background:#FCC; float:right}/*寬度設(shè)置為百分?jǐn)?shù),以實(shí)現(xiàn)自適應(yīng)*/   
  12. </style>  
  13. </head>  
  14.   
  15. <body>  
  16.     <div class="head">head</div>  
  17.     <div class="left">left</div>  
  18.     <div class="right">right</div>  
  19. </body>  
  20. </html>  
  21.   

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/hunhebuju01.html

混合布局02

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3.     <meta http-equiv="Content-Type" content="text/html;          charset=utf-8" />  
  4.     <title>混合布局</title>  
  5. <style>  
  6.     body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7.     div{ text-align:center; line-height:50px}   
  8.     .head, .main, .footer{ width:960px; margin:0 auto}   
  9.     .head{ height:100px;background:#9CF}   
  10.     .left{ width:240px; height:600px; background:#ccc; float:left}   
  11.     .right{ width:720px; height:600px;background:#FCC; float:right}/*寬度設(shè)置為固定值*/   
  12.     .footer{ height:50px; background:#9F9; clear:both}   
  13. </style>  
  14. </head>  
  15.   
  16. <body>  
  17.     <div class="head">head</div>  
  18.     <div class="main">  
  19.     <div class="left">left</div>  
  20.     <div class="right">right</div>  
  21. </div>  
  22.     <div class="footer">footer</div>  
  23. </body>  
  24. </html>  

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/hunhebuju02.html

混合布局03

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>混合布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .head, .main, .footer{ width:960px; margin:0 auto}/*head main及footer設(shè)置固定寬度*/   
  9. .head{ height:100px;background:#9CF}   
  10. .left{ width:220px; height:600px; background:#ccc; float:left}   
  11. .right{ width:740px; height:600px;background:#FCC; float:right}   
  12. .r_sub_left{ width:540px; height:600px; background:#9C3; float:left}   
  13. .r_sub_right{ width:200px; height:600px; background:#9FC; float:right}/*540px+200px=740px 注意寬度值的設(shè)置*/   
  14. .footer{ height:50px; background:#9F9; clear:both}/*使用clear:both清除浮動*/   
  15. </style>  
  16. </head>  
  17.   
  18. <body>  
  19. <div class="head">head</div>  
  20. <div class="main">  
  21.     <div class="left">left</div>  
  22.     <div class="right">  
  23.         <div class="r_sub_left">sub_left   
  24.         </div>  
  25.         <div class=" r_sub_right">sub_right   
  26.         </div>  
  27.     </div>  
  28. </div>  
  29. <div class="footer">footer</div>  
  30. </body>  
  31.   
  32. </html>  

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/hunhebuju03.html

混合布局04

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>混合布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .main{ width:960px; margin:0 auto}/*footer和main未設(shè)置寬度*/   
  9. .head{ height:100px;background:#9CF}   
  10. .left{ width:220px; height:600px; background:#ccc; float:left}   
  11. .right{ width:740px; height:600px;background:#FCC; float:right}   
  12. .r_sub_left{ width:540px; height:600px; background:#9C3; float:left}   
  13. .r_sub_right{ width:200px; height:600px; background:#9FC; float:right}/*540px+200px=740px 注意寬度值的設(shè)置*/   
  14. .footer{ height:50px; background:#9F9; clear:both}/*使用clear:both清除浮動*/   
  15. </style>  
  16. </head>  
  17.   
  18. <body>  
  19. <div class="head">head</div>  
  20. <div class="main">  
  21.     <div class="left">left</div>  
  22.     <div class="right">  
  23.         <div class="r_sub_left">sub_left   
  24.         </div>  
  25.         <div class=" r_sub_right">sub_right   
  26.         </div>  
  27.     </div>  
  28. </div>  
  29. <div class="footer">footer</div>  
  30. </body>  
  31. </html>  

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/hunhebuju04.html

混合布局05(自適應(yīng))

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <html">  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>混合布局</title>  
  5. <style>  
  6. body{ margin:0; padding:0; font-size:30px; font-weight:bold}   
  7. div{ text-align:center; line-height:50px}   
  8. .head{ height:100px;background:#9CF}   
  9. .left{ width:20%; height:600px; background:#ccc; float:left}   
  10. .main{margin:0 30%;height:600px; background:#9CC }   
  11. .right{ width:20%; height:600px;background:#FCC; float:right}/*寬度均設(shè)為百分比*/   
  12. .footer{ height:50px; background:#9F9; clear:both}   
  13. </style>  
  14. </head>  
  15.   
  16. <body>  
  17.     <div class="head">head</div>  
  18.     <div class="left">left</div>  
  19.     <div class="right">right</div>  
  20.     <div class="main">main</div>  
  21.     <div class="footer">footer</div>  
  22. </body>  
  23. </html>  

DEMO:http://Lovejulyer.github.io/Source_Code/Blog_demo/Codes2/hunhebuju05.html

在網(wǎng)頁制作中,面對設(shè)計圖,網(wǎng)頁制作人員一般要遵循的原則是:先考慮設(shè)計圖中的文字內(nèi)容和內(nèi)容模塊之間的關(guān)系,重點(diǎn)放在編寫html結(jié)構(gòu)和語義化,然后考慮布局和變現(xiàn)形式。
倡導(dǎo)結(jié)構(gòu),樣式,行為分離。舉例:網(wǎng)頁換膚——相同HTML結(jié)構(gòu),不同CSS樣式。

相關(guān)文章

最新評論

来安县| 孟村| 齐齐哈尔市| 大方县| 福建省| 陆良县| 台州市| 高淳县| 汤阴县| 高唐县| 樟树市| 临邑县| 临澧县| 江门市| 阳春市| 汤阴县| 瑞昌市| 嵊州市| 夏津县| 锡林郭勒盟| 西藏| 武邑县| 苗栗县| 威信县| 南部县| 开远市| 孝感市| 汪清县| 工布江达县| 江华| 万州区| 大洼县| 弥渡县| 溧阳市| 米林县| 金华市| 铜川市| 合肥市| 福贡县| 四平市| 平山县|