028-86922220
建站资讯

网站建设资讯

为你提供网站建设行业资讯、网站优化知识、主机域名邮箱、网站开发常见问题等。

书写高效CSS注意的七个方面分别是什么

这期内容当中小编将会给大家带来有关书写高效CSS注意的七个方面分别是什么,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

创新互联公司致力于互联网品牌建设与网络营销,包括成都网站制作、成都网站设计、SEO优化、网络推广、整站优化营销策划推广、电子商务、移动互联网营销等。创新互联公司为不同类型的客户提供良好的互联网应用定制及解决方案,创新互联公司核心团队十多年专注互联网开发,积累了丰富的网站经验,为广大企业客户提供一站式企业网站建设服务,在网站建设行业内树立了良好口碑。

你对如何书写高效CSS是否熟悉,这里和大家分享一下书写高效CSS注意的七个方面,主要包括使用外联样式替代行间样式或者内嵌样式,建议使用link引入外部样式表等内容。

CSS经验分享:书写高效CSS注意的七个方面

随着CSS网页布局的应用越来越广泛,更多的CSSer开始书写CSS,如何才能写出高效规范的CSS代码呢,本文向大家介绍一下必须要注意的七个方面:

一、使用外联样式替代行间样式或者内嵌样式

不推荐使用行间样式

ExampleSourceCode

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    Pagetitle-52css.comtitle> head> <body> <pstylepstyle="color:red">...p> body> html></pre><p>不推荐使用内嵌样式</p><p>ExampleSourceCode</p><pre>"http://www.w3.org/TR/html4/strict.dtd"><htmllanghtmllang="en"> <head> <metahttp-equivmetahttp-equiv="Content-Type"content="text/html;charset=utf-8"/> <title>Pagetitle-52css.comtitle> <styletypestyletype="text/css"media="screen"> p{color:red;}  style> head> <body>...body> html></pre><p>推荐使用外联样式</p><p>ExampleSourceCode</p><pre>"http://www.w3.org/TR/html4/strict.dtd"> <htmllanghtmllang="en"> <head> <metahttp-equivmetahttp-equiv="content-type"content="text  <title>Pagetitle-52css.comtitle> <linkrellinkrel="stylesheet"href="name.css"type="text/css"media="screen"/> head> <body>...body> html></pre><p><strong>二、建议使用link引入外部样式表</strong></p><p>为了兼容老版本的浏览器,建议使用link引入外部样式表的方来代替@import导入样式的方式.</p><p>译者注:@import是CSS2.1提出的所以老的浏览器不支持,点击查看@import的兼容性。</p><p>@import和link在使用上会有一些区别,利用二者之间的差异,可以在实际运用中进行权衡。</p><p>关于@import和link方式的比较在52CSS.com上有几篇文章可以拓展阅读。</p><p>不推荐@import导入方式</p><p>ExampleSourceCode</p><pre> "http://www.w3.org/TR/html4/strict.dtd"> <htmllanghtmllang="en"> <head> <metahttp-equivmetahttp-equiv="content-type"content="text  <title>Pagetitle-52css.comtitle> <styletypestyletype="text/css"media="screen"> @importurl("styles.css");  style> head> <body>...body> html></pre><p>推荐引入外部样式表方式</p><p>ExampleSourceCode</p><pre>"http://www.w3.org/TR/html4/strict.dtd"><htmllanghtmllang="en"><head> <metahttp-equivmetahttp-equiv="content-type"content="text  <title>Pagetitle-52css.comtitle> <linkrellinkrel="stylesheet"href="name.css"type="text/css"media="screen"/> head> <body>...body> html></pre><p><strong>三、使用继承</strong></p><p>ExampleSourceCode</p><pre>低效率的   p{font-family:arial,helvetica,sans-serif;}  #container{font-family:arial,helvetica,sans-serif;}  #navigation{font-family:arial,helvetica,sans-serif;}  #content{font-family:arial,helvetica,sans-serif;}  #sidebar{font-family:arial,helvetica,sans-serif;}  h2{font-family:georgia,times,serif;}   高效的   body{font-family:arial,helvetica,sans-serif;}  body{font-family:arial,helvetica,sans-serif;}  h2{font-family:georgia,times,serif;}</pre><p><strong>四、使用多重选择器</strong></p><p>ExampleSourceCode</p><pre>低效率的   h2{color:#236799;}  h3{color:#236799;}  h4{color:#236799;}  h5{color:#236799;}   高效的   h2,h3,h4,h5{color:#236799;}</pre><p><strong>五、使用多重声明</strong></p><p>ExampleSourceCode</p><pre>低效率的   p{margin:001em;}  p{background:#ddd;}  p{color:#666;}   译者注:对于十六进制颜色值,个人偏向于色值不缩写且英文字母要大写的方式.   高效的   p{margin:001em;background:#ddd;color:#666;}</pre><p><strong>六、使用简记属性</strong></p><p>ExampleSourceCode</p><pre>低效率的   body{font-size:85%;font-family:arial,helvetica,sans-serif;  background-image:url(image.gif);background-repeat:no-repeat;  background-position:0100%;margin-top:1em;margin-right:1em;  margin-bottom:0;margin-left:1em;padding-top:10px;  padding-right:10px;padding-bottom:10px;padding-left:10px;  border-style:solid;border-width:1px;border-color:red;color:#222222;   高效的   body{font:85%arial,helvetica,sans-serif;  background:url(image.gif)no-repeat0100%;margin:1em1em0;  padding:10px;border:1pxsolidred;color:#222;}</pre><p><strong>七、避免使用!important</strong></p><p>ExampleSourceCode</p><pre>慎用写法   #news{background:#ddd!important;}  特定情况下可以使用以下方式提高权重级别  #container#news{background:#ddd;}  body#container#news{background:#ddd;}</pre><p>上述就是小编为大家分享的书写高效CSS注意的七个方面分别是什么了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。</p>            
            
                        <br>
            本文标题:书写高效CSS注意的七个方面分别是什么            <br>
            网站地址:<a href="http://www.whjierui.cn/article/jojsdg.html">http://www.whjierui.cn/article/jojsdg.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/cpdhep.html">ODCC2020开放数据中心峰会亮点剧透之智能无损网络</a>
                </li><li>
                    <a href="/article/cpdhee.html">css中如何设置背景图片的大小</a>
                </li><li>
                    <a href="/article/cpdppg.html">有了双拼用三拼!终端中五位秒下域名yiqiju.com</a>
                </li><li>
                    <a href="/article/cpdhdp.html">探秘PHPnumber_format函数原理及实例解析</a>
                </li><li>
                    <a href="/article/cpdhdo.html">商城网站建设设计六要素</a>
                </li>        </ul>
    </div>
</div>
<footer>
    <div class="foot-top">
        <ul>
            <li>
                <div class="title">关于美图云海</div>
                <div class="tbox">
                    <div class="txt">
                        美图云海专注于网站建设、小程序开发,
                        <br /> 用心做好每一个网站,懂您所需、做您所想!
                        <br /> 我们比其他网络公司做的更好、做的更多,
                        <br /> 为客户创造更大的价值,让客户更省心!
                    </div>
                    <a rel="nofollow" href="javascript:;" class="more">MORE</a>
                </div>
            </li>
            <li>
                <div class="title">相关专题</div>
                <div class="tbox">
                    <a href="javascript:;" class="link">企业官网定制</a>
                    <a href="javascript:;" class="link">小程序开发</a>
                    <a href="javascript:;" class="link">品牌网站设计</a>
                    <a href="javascript:;" class="link">网站建设标签</a>
                    <a href="javascript:;" class="link">乐山网站建设</a>
                    <a href="javascript:;" class="link">高端网站设计</a>
                    <a href="javascript:;" class="link">公司做网站</a>
                </div>
            </li>
            <li>
                <div class="title">凭什么选择我们</div>
                <div class="tbox">
                    <a class="link">专业设计团队</a>
                    <a class="link">快速响应服务</a>
                    <a class="link">7个软件著作权</a>
                    <a class="link">已服务3000+客户</a>
                    <a class="link">项目检测具体全面</a>
                    <a class="link">技术研发能力强劲</a>
                    <a class="link">深度符合SEO优化</a>
                    <a class="link">15项设计奖项</a>
                    <a class="link">完善的制作流程</a>
                    <a class="link">售后服务让您省心</a>
                </div>
            </li>
            <li>
                <div class="title">网站设计案例</div>
                <div class="tbox">
                    <ul>
                        <li>
                            <a href="javascript:;" target="_blank">
                                <div class="img"><img src="/Public/Home/images/gebaili.jpg" alt="哥百利" />
                                </div>
                                <div class="tboxs">
                                    <div class="t1">哥百利</div>
                                    <div class="t2">家具研发、设计、生产、服务为一体的专业实木家具订做企业</div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" target="_blank">
                                <div class="img"><img src="/Public/Home/images/cdshujin.jpg" alt="蜀锦在线" /></div>
                                <div class="tboxs">
                                    <div class="t1">蜀锦在线</div>
                                    <div class="t2">汽车行业网站建设</div>
                                </div>
                            </a>
                        </li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
    <div class="foot-center">
        <ul>
            <li>
                <div class="f-ewm"><img alt="美图云海微信公众号" src="/Public/Home/images/ewm.jpg" /></div>
                <div class="tbox ewm">
                    <div class="t1">扫一扫关注</div>
                    <div class="t2">专业团队为您解答</div>
                </div>
            </li>
            <li>
                <div class="tbox tel">
                    <div class="t1">电话/邮箱</div>
                    <div class="t2">400-028-6601 / 028-86922220<br>631063699@qq.com</div>
                </div>
            </li>
            <li>
                <div class="tbox sz">
                    <div class="t1">成都(总部)</div>
                    <div class="t2">成华区 双林路22号仁禾商务楼5F<br> 大客户专线:13518219792
                    </div>
                </div>
            </li>
            <li>
                <div class="tbox gz">
                    <div class="t1">网站建设(乐山站)</div>
                    <div class="t2">
                        乐山市市中区瑞祥路一段1507号
                        <br /> 028-86922220
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="foot-button">
        <div class="link-box" style="width:100%;float:none;">
            <div class="a-box"></div>
            <div style="border-top:1px solid #ebebeb;font-size:12px;color:#666666;line-height:2;padding-top:20px;margin-top:20px;">
                业务范围包括企业网站建设、商城系统开发、品牌网站设计、旅游网站制作、英文外贸网站、教育培训门户网站开发、微信手机移动端开发、响应式网站建设、微信小程序开发、APP定制和其他类型网站定制等。
                <br>服务区域包括成都市锦江区、青羊区、武侯区、金牛区、成华区、龙泉驿、温江、新都、高新区、成都市以及全国各地接受异地服务商的公司企业或者机构。
                <br>
                <div class="a-box"><span><b>友情链接</b></span>
                    <a href="http://www.cxjianzhan.com/seo/" title="seo推广公司" target="_blank">seo推广公司</a><a href="http://www.shjinzhi.cn/" title="活动板房" target="_blank">活动板房</a><a href="https://www.cdcxhl.com/" title="网站建设" target="_blank">网站建设</a><a href="http://www.cxjianzhan.com/" title="网络营销推广" target="_blank">网络营销推广</a><a href="http://www.cdxwcx.cn/tuoguan/yaan.html" title="雅安主机托管" target="_blank">雅安主机托管</a><a href="http://www.zwzsheng.com/" title="zwzsheng.com" target="_blank">zwzsheng.com</a><a href="http://www.hkccoic.com/" title="四川國際商會" target="_blank">四川國際商會</a><a href="http://www.cqcxhl.com/" title="网站建设公司" target="_blank">网站建设公司</a><a href="http://www.gxwzsj.com/" title="广西网站建设" target="_blank">广西网站建设</a><a href="http://www.kjlewan.com/" title="kjlewan.com" target="_blank">kjlewan.com</a>                </div>
            </div>
            <div class="copyright">©2025 青羊区美图云海设计工作室(个体工商户)乐山站   蜀ICP备19037934号</div>
        </div>
    </div>
</footer>
<div class="fixed-contact-wrap show">
    <ul class="item-list clearfix">
        <li class="phone">
            <a rel="nofollow" target="_blank" href="tel:028-86922220"><i
                    class="icon"></i><strong>028-86922220</strong></a>
        </li>
        <li class="qq">
            <a rel="nofollow" target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes"><i
                    class="icon"></i><strong> 244261566</strong></a>
        </li>
        <li class="back-top">
            <a href="#" rel="nofollow" class="back-to-top"><i class="icon"></i><strong> 回到顶部</strong></a>
        </li>
    </ul>
</div>
<script type="text/javascript">
    //右侧联系我们悬浮窗
    $(".fixed-contact-wrap").hover(function () {
        $(this).addClass("active");
    }, function () {
        $(this).removeClass("active");
    })
    function show_phone_menu() {
        $(".right-side ul").toggle();
    }
</script>

</body>
</html>

<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>