CSS使用須知

來源:互聯網
上載者:User

1、文字垂直置中,需設定元素高height和行高line-height相等

2、不要使用過小的圖片做背景平鋪如:1px,寬高1px 的圖片平鋪出一個寬高 200px 的地區,需要 200*200=40, 000 次,佔用資源。

3、無邊框,推薦的寫法是 border:none;

4、慎用 * 萬用字元,所謂萬用字元,就是將 CSS 中的所有標籤均起作用,大大的佔用資源。

5、堅決不用 CSS 運算式,css就是css,扯上javascript的expression進來,不但效能影響了,獨立性也不行。

6、使用引用樣式表,而不是通過 @import 匯入,引入樣式表是載入完css才渲染頁面,使用者體驗比較好,不會出現介面初始化紊亂的現象。  7、知道什麼時候用什麼圖片格式
       png是壓縮比較少的圖片格式,很清晰,但IE6不支援PNG-24,卻完全支援PNG-8,(如果是不透明的PNG-24,IE6也是完美支援)        gif用於要求不高的小表徵圖,相容性很好        jpg是壓縮很多的圖片,也是使用最多的

 8、IE6浮動標籤的margin雙倍邊距bug問題:加上display:inline解決

 9、div層置中於瀏覽器

水平置中: div { width:400px; height:400px; margin:0 auto; } //註:html代碼前面一定要加上下列w3c聲明,否則無法置中。

  置中置中: div{position:absolute;top:50%; left:50%; margin:-100px 0 0 -100px;width:200px; height:200px; border:1px solid red;}


 10、處理文字經常用的:
         文字自動換行:word-wrap:break-word;                文字強制同一行:white-space: nowrap;              超出行用“…” text-overflow: ellipsis;          超出範圍隱藏:overflow: hidden;

11、經常用的命名規則 
        頭:header 
        內容:content/container 
        尾:footer 
        導航:nav 
        側欄:sidebar 
        欄目:column 
        頁面外圍控制整體布局寬度:wrapper 
        左右中:left right center

12、為了相容各瀏覽器需還原標籤樣式

頁面聲明統一採用XHTML

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

全域標籤清除

<style type="text/css">

body,div,label,span,ul,li{border:none;padding:0;margin:0;}

body,button, input, select, textarea {font: 12px/1.5 '宋體', Arial, sans-serif; }

a:focus{outline: none;-moz-outline-style: none; }

ul, ol, li {list-style: none; }

img{ border:0px;} 

</style>

相關文章

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.