成都创新互联网站制作重庆分公司

书写高效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://cxhlcq.com/article/jojsdg.html">http://cxhlcq.com/article/jojsdg.html</a>
        </div>
    </div>
</div>
<div class="other container">
    <h3>其他资讯</h3>
    <ul>
        <li>
                <a href="/article/gdicjo.html">ngAnimate插件有什么用</a>
            </li><li>
                <a href="/article/gdicpi.html">jquery全选和反选</a>
            </li><li>
                <a href="/article/gdisoj.html">C++Primer_笔记_异常处理</a>
            </li><li>
                <a href="/article/gdisdg.html">使用linux的brctl命令以太网网桥管理</a>
            </li><li>
                <a href="/article/gdisop.html">redis实现缓存的两种方式</a>
            </li>    </ul>
</div>
<div class="footer">
    <div class="foota container">
        <div class="foot_nav fl col-lg-8 col-md-8 col-sm-12 col-xs-12">
            <ul>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站制作</h3>
                    <a href="http://www.cdxwcx.cn/" target="_blank">成都网站制作</a><a href="http://www.cdxwcx.cn/bj/" target="_blank">网站制作报价</a><a href="http://www.cxjianzhan.com/" target="_blank">网站制作公司</a><a href="http://www.cxjianzhan.com/mobile/" target="_blank">手机网站制作</a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站制作</a><a href="http://www.cxjianzhan.com/" target="_blank">网站制作</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>企业服务</h3>
                    <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站免费收录</a><a href="https://www.cdcxhl.com/service/licence.html" target="_blank">药房许可证</a><a href="https://www.cdcxhl.com/weihu/chengdu.html" target="_blank">成都网站维护</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文发布平台</a><a href="https://www.cdcxhl.com/service/beian.html" target="_blank">网站备案</a><a href="https://www.cdcxhl.com/hangyead/" target="_blank">一元广告</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站建设</h3>
                    <a href="http://www.cdweb.net/solve/" target="_blank">网站建设方案</a><a href="https://www.cdcxhl.com/" target="_blank">网站建设公司</a><a href="http://chengdu.cdcxhl.cn/jianshe/" target="_blank">成都网站建设</a><a href="http://www.cdxtjz.cn/" target="_blank">成都网站建设</a><a href="http://m.cdcxhl.cn/seo/" target="_blank">营销网站建设</a><a href="http://www.cdxwcx.cn/" target="_blank">成都网站建设</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>服务器托管</h3>
                    <a href="https://www.cdcxhl.com/tuoguan/yidong/" target="_blank">移动服务器托管</a><a href="https://www.cdxwcx.com/jifang/yaan.html" target="_blank">雅安服务器托管</a><a href="https://www.cdcxhl.com/tuoguan.html" target="_blank">成都服务器托管</a><a href="https://www.cdcxhl.com/idc/deyang.html" target="_blank">德阳服务器托管</a><a href="https://www.cdcxhl.com/idc/ershu.html" target="_blank">二枢服务器托管</a><a href="https://www.cdcxhl.com/idc/yaan.html" target="_blank">雅安服务器托管</a>                </li>
            </ul>
        </div>
        <div class="footar fl col-lg-4 col-md-4 col-sm-12 col-xs-12">
            <p>全国免费咨询:</p>
            <b>400-028-6601</b>
            <p>业务咨询:028-86922220 / 13518219792</p>
            <p>节假值班:18980820575 / 13518219792</p>
            <p>联系地址:成都市太升南路288号锦天国际A幢1002号</p>
        </div>
    </div>
    <div class="footb">
        <div class="copy container">
            <div class="fl">Copyright © 成都创新互联科技有限公司重庆分公司  <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备2021005571号</a></div>
            <!--<div class="fr"><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:<a href="https://www.cdcxhl.com/" target="_blank">创新互联</a></div>-->
        </div>
    </div>
    <div class="link">
        <div class="container">
            友情链接::
            <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a>
            <a href="https://www.cdcxhl.com/city/chongqing.html" target="_blank">重庆网站建设</a>
            <a href="">四川网站建设</a>
            <a href="">重庆建设网站</a>
            <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">移动服务器托管</a>
            <a href="http://www.cdfuwuqi.com/" target="_blank">成都服务器托管</a>
            <a href="https://www.cdcxhl.cn/" target="_blank">云服务器</a>
            <a href="http://www.cdhuace.com/" target="_blank">广告设计制作</a>
            <a href="https://www.cdcxhl.com/sheji/chongqing.html" target="_blank">重庆网页设计</a>
            <a href="https://www.cdcxhl.com/zuo/chongqing.html" target="_blank">重庆做网站</a>
            <a href="https://www.cdcxhl.com/zhizuo/chongqing.html" target="_blank">重庆网站制作</a>
            <a href="">重庆网站建设</a>
            <a href="">重庆网站公司</a>
            <a href="">渝中网站制作</a>
            <a href="">重庆网站设计</a>
        </div>
    </div>
</div>
<div class="foot">
    <ul class="public-celan">
        <li>
            <a href="https://p.qiao.baidu.com/cps3/chatIndex?siteToken=6ce441ff9e2d6bedbdfc2a4138de449e&speedLogId=162260383240185e3_1622603832401_02407&eid=6256368&reqParam=%7B%22from%22%3A1%2C%22sessionid%22%3A%22-100%22%2C%22siteId%22%3A%2211284691%22%2C%22tid%22%3A%22-1%22%2C%22userId%22%3A%226256368%22%2C%22ttype%22%3A1%2C%22pageId%22%3A0%7D" target="_blank" class="a1 db tc">
                <img src="/Public/Home/img/icon-23.png" alt="" class="db auto">
                <span class="span-txt">在线咨询</span>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" class="a1 db tc">
                <img src="/Public/Home/img/icon-24.png" alt="" class="db auto">
                <span class="span-txt">电话咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="a1 db tc">
                <img src="/Public/Home/img/icon-25.png" alt="" class="db auto">
                <span class="span-txt">QQ咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=532337155&Site=&Menu=yes" class="a1 db tc public-yuyue-up">
                <img src="/Public/Home/img/icon-26.png" alt="" class="db auto">
                <span class="span-txt">预约顾问</span>
            </a>
        </li>
    </ul>
</div>
<div class="customer">
    <dl class="icon1">
        <dt>
            <a href="tencent://message/?uin=1683211881&Site=&Menu=yes">
                <i class="iconT"><img src="/Public/Home/img/QQ.png" alt=""></i>
                <p>在线咨询</p>
            </a>
        </dt>
    </dl>
    <dl class="icon2">
        <dt><i><img src="/Public/Home/img/weixin.png" alt=""></i><p>微信咨询</p></dt>
        <dd><img src="/Public/Home/img/ewm.png"></dd>
    </dl>
    <dl class="icon3">
        <dt><i><img src="/Public/Home/img/dianhua.png" alt=""></i><p>电话咨询</p></dt>
        <dd>
            <p>028-86922220(工作日)</p>
            <p>18980820575(7×24)</p>
        </dd>
    </dl>
    <dl class="icon4">
        <dt class="sShow">
            <a href="tencent://message/?uin=244261566&Site=&Menu=yes">
                <i><img src="/Public/Home/img/dengji.png" alt=""></i><p>提交需求</p>
            </a>
        </dt>
    </dl>
    <dl class="icon5">
        <dt class="gotop">
            <a href="#top">
                <i><img src="/Public/Home/img/top.png" alt=""></i><p>返回顶部</p>
            </a>
        </dt>
    </dl>
</div>
</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>