亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        css代碼優(yōu)化的12個(gè)技巧

        字號(hào):


            1.id 規(guī)則
            2.class 規(guī)則
            3.標(biāo)簽規(guī)則
            4.通用規(guī)則
            對(duì)效率地普遍認(rèn)識(shí)是從steve souders在2009年出版地《高性能網(wǎng)站建設(shè)進(jìn)階指南》開始,雖然該書中羅列地更加詳細(xì),但你也可以在這里查看完整地引用列表,也可以在谷歌地《高效css選擇器地最佳實(shí)踐》中查看更多地細(xì)節(jié).
            本文我想分享一些我在編寫高性能css中用到地簡(jiǎn)單例子和指南.這些都是受到mdn 編寫地高效css指南地啟發(fā),并遵循類似地格式.
            一、避免過度約束
            一條普遍規(guī)則,不要添加不必要地約束.
            代碼如下:
            // 糟糕的寫法
            ul#someid {..}
            .menu#otherid{..}
            // 優(yōu)秀的
            #someid {..}
            #otherid {..}
            二、后代選擇符最爛
            不僅性能低下而且代碼很脆弱,html代碼和css代碼嚴(yán)重耦合,html代碼結(jié)構(gòu)發(fā)生變化時(shí),css也的修改,這是多么糟糕的寫法,特別是在大公司里,寫html和css地往往不是同一個(gè)人.
            代碼如下:
            // 爛透了
            html div tr td {..}
            三、避免鏈?zhǔn)剑ń患┻x擇符
            這和過度約束地情況類似,更明智地做法是簡(jiǎn)單地創(chuàng)建一個(gè)新地css類選擇符.
            代碼如下:
            // 糟糕的寫法
            .menu.left.icon {..}
            // 優(yōu)秀的
            .menu-left-icon {..}
            四、堅(jiān)持kiss原則
            想象我們有如下地dom:
            代碼如下:
            <ul id=navigator>
            <li><a href=# class=twitter>twitter</a></li>
            <li><a href=# class=facebook>facebook</a></li>
            <li><a href=# class=dribble>dribbble</a></li>
            </ul>
            下面是對(duì)應(yīng)地規(guī)則……
            代碼如下:
            // 糟糕的寫法
            #navigator li a {..}
            // 優(yōu)秀的
            #navigator {..}
            五、使用復(fù)合(緊湊)語法
            盡可能使用復(fù)合語法.
            代碼如下:
            // 糟糕的寫法
            .someclass {
            padding-top: 20px;
            padding-bottom: 20px;
            padding-left: 10px;
            padding-right: 10px;
            background: #000;
            background-image: url(../imgs/carrot.png);
            background-position: bottom;
            background-repeat: repeat-x;
            }
            // 優(yōu)秀的
            .someclass {
            padding: 20px 10px 20px 10px;
            background: #000 url(../imgs/carrot.png) repeat-x bottom;
            }
            六、避免不必要地命名空間
            代碼如下:
            // 糟糕的寫法
            .someclass table tr.otherclass td.somerule {..}
            //優(yōu)秀的
            .someclass .otherclass td.somerule {..}
            七、避免不必要地重復(fù)
            盡可能組合重復(fù)地規(guī)則.
            代碼如下:
            // 糟糕的寫法
            .someclass {
            color: red;
            background: blue;
            font-size: 15px;
            }
            .otherclass {
            color: red;
            background: blue;
            font-size: 15px;
            }
            // 優(yōu)秀的
            .someclass, .otherclass {
            color: red;
            background: blue;
            font-size: 15px;
            }
            八、盡可能精簡(jiǎn)規(guī)則
            在上面規(guī)則地基礎(chǔ)上,你可以進(jìn)一步合并不同類里地重復(fù)地規(guī)則.
            代碼如下:
            // 糟糕的寫法
            .someclass {
            color: red;
            background: blue;
            height: 150px;
            width: 150px;
            font-size: 16px;
            }
            .otherclass {
            color: red;
            background: blue;
            height: 150px;
            width: 150px;
            font-size: 8px;
            }
            // 優(yōu)秀的
            .someclass, .otherclass {
            color: red;
            background: blue;
            height: 150px;
            width: 150px;
            }
            .someclass {
            font-size: 16px;
            }
            .otherclass {
            font-size: 8px;
            }
            九、避免不明確地命名約定
            最好使用表示語義地名字.一個(gè)優(yōu)秀的css類名應(yīng)描述它是什么而不是它像什么.
            十、避免 !importants
            其實(shí)你應(yīng)該也可以使用其他優(yōu)質(zhì)地選擇器.
            十一、遵循一個(gè)標(biāo)準(zhǔn)地聲明順序
            雖然有一些排列css屬性順序常見地方式,下面是我遵循地一種流行方式.
            代碼如下:
            .someclass {
            /* positioning */
            /* display & box model */
            /* background and typography styles */
            /* transitions */
            /* other */
            }
            十二、組織優(yōu)秀的代碼格式
            代碼地易讀性和易維護(hù)性成正比.下面是我遵循地格式化方法.
            代碼如下:
            // 糟糕的寫法
            .someclass-a, .someclass-b, .someclass-c, .someclass-d {
            ...
            }
            // 優(yōu)秀的
            .someclass-a,
            .someclass-b,
            .someclass-c,
            .someclass-d {
            ...
            }
            // 優(yōu)秀的做法
            .someclass {
            background-image:
            linear-gradient(#000, #ccc),
            linear-gradient(#ccc, #ddd);
            box-shadow:
            2px 2px 2px #000,
            1px 4px 1px 1px #ddd inset;
            }
            顯然,這里只講述了少數(shù)地規(guī)則,是我在我自己地css中,本著更高效和更易維護(hù)性而嘗試遵循地規(guī)則.如果你想閱讀更多地知識(shí),我建議閱讀mdn上地編寫高效地css和谷歌地優(yōu)化瀏覽器渲染指南.