资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

书写CSS时需要的七个方面指的是什么

今天就跟大家聊聊有关书写CSS时需要的七个方面指的是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册网站空间、营销软件、网站建设、龙亭网站维护、网站推广。

书写CSS时注意的七个方面

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

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

◆不推荐使用行间样式

XML/HTML代码

                    Page title - book.chinaz.comtitle>     head>       <body>     <p style="color: red"> ... p>       body>       html></pre><p>◆不推荐使用内嵌样式</p><p>XML/HTML代码</p><pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"    "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en">       <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />     <title>Page title - book.chinaz.comtitle>       <style type="text/css" media="screen">     p { color: red; }       style>       head>       <body>... body>       html></pre><p>◆推荐使用外联样式</p><p>XML/HTML代码</p><pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"    "http://www.w3.org/TR/html4/strict.dtd">     <html lang="en">     <head>       <meta http-equiv="content-type" content="text       <title>Page title - book.chinaz.comtitle>       <link rel="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提出的所以老的浏览器不支持。</p><p>@import和link在使用上会有一些区别, 利用二者之间的差异,可以在实际运用中进行权衡。</p><p>关于@import和link方式的比较在52CSS.com上有几篇文章可以拓展阅读。</p><p>◆不推荐@import导入方式</p><p>XML/HTML代码</p><pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"    "http://www.w3.org/TR/html4/strict.dtd">       <html lang="en">     <head>       <meta http-equiv="content-type" content="text       <title>Page title - 52css.comtitle>       <style type="text/css" media="screen">       @import url("styles.css");      style>     head>     <body> ... body>     html></pre><p>◆推荐引入外部样式表方式</p><p>XML/HTML代码</p><pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"    "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head>     <meta http-equiv="content-type" content="text       <title>Page title - blog.huangchao.orgtitle>     <link rel="stylesheet" href="name.css" type="text/css" media="screen" />     head>       <body> ... body>       html></pre><p><strong>三、使用继承</strong></p><p>低效率的</p><p>CSS代码</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; }</pre><p>高效的</p><p>CSS代码</p><pre>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>低效率的</p><p>CSS代码</p><pre>h2 { color: #236799; }       h3 { color: #236799; }      h4 { color: #236799; }      h5 { color: #236799; }</pre><p>高效的</p><p>CSS代码</p><pre>h2, h3, h4, h5 { color: #236799; }</pre><p><strong>五、使用多重声明</strong></p><p>低效率的</p><p>CSS代码</p><pre>p { margin: 0 0 1em; }      p { background: #ddd; }      p { color: #666; }</pre><p>译者注: 对于十六进制颜色值,个人偏向于色值不缩写且英文字母要大写的方式.</p><p>高效的</p><p>CSS代码</p><pre>p { margin: 0 0 1em; background: #ddd; color: #666; }</pre><p><strong>六、使用简记属性</strong></p><p>低效率的</p><p>CSS代码</p><pre>body { font-size: 85%; font-family: arial, helvetica, sans-serif; background-image: url(image.gif);   background-repeat: no-repeat; background-position: 0 100%; 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;</pre><p>高效的</p><p>CSS代码</p><pre>body { font: 85% arial, helvetica, sans-serif; background: url(image.gif) no-repeat 0 100%;   margin: 1em 1em 0; padding: 10px; border: 1px   solid red; color: #222; }</pre><p><strong> 七、避免使用 !important</strong></p><p>慎用写法</p><p>CSS代码</p><pre>#news { background: #ddd !important; }</pre><p>特定情况下可以使用以下方式提高权重级别</p><p>CSS代码</p><pre>#container #news { background: #ddd; }      body #container #news { background: #ddd; }</pre><p>看完上述内容,你们对书写CSS时需要的七个方面指的是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。</p>            
            
                        <br>
            当前名称:书写CSS时需要的七个方面指的是什么            <br>
            文章网址:<a href="http://cdkjz.cn/article/iisdpo.html">http://cdkjz.cn/article/iisdpo.html</a>
        </div>
        <div class="g-return-wrapper clearfix">
            <a href="http://www.cdkjz.cn/" class="home">返回首页</a>
            <a href="http://www.cdkjz.cn/news/" class="column">了解更多建站资讯</a>
        </div>
    </div>
</div>
<div class="full-related-news">
    <h3 class="related-title">相关资讯</h3>
    <div class="related-news weblg">
        <ul class="clearfix">
            <li>
                    <a href="/article/ddsghos.html">
                        <h2 class="title">如何改java代码 java调整代码格式快捷键</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsjooh.html">
                        <h2 class="title">zblog在线问答插件 zbloglt</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsghhh.html">
                        <h2 class="title">阿里聚安全停止服务器 阿里聚安全验证不了</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsghjh.html">
                        <h2 class="title">wordpress代替 wordpress neve</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsgheg.html">
                        <h2 class="title">zblog发帖插件 zblog使用</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsghij.html">
                        <h2 class="title">c语言函数的加减乘除 c语言函数加减乘除运算编程</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsghis.html">
                        <h2 class="title">zblog源码销售平台 zblog商城</h2>
                    </a>
                </li><li>
                    <a href="/article/ddsghph.html">
                        <h2 class="title">优秀简洁java代码 java代码例子讲解</h2>
                    </a>
                </li>        </ul>
    </div>
</div>
<div class="full-icontact-cover m-ft-contact">
    <div class="weblg">
        <div class="clearfix content">
            <div class="motto">
                多年建站经验
            </div>
            <div class="info">
                <h3>多一份参考,总有益处</h3>
                <h2> 联系快上网,免费获得专属《策划方案》及报价</h2>
                <div class="msg">
                    <p>咨询相关问题或预约面谈,可以通过以下方式与我们联系</p>
                    <h4> 大客户专线   成都:<a
                            href="tel:+13518219792" rel="nofollow">13518219792</a>
                          座机:<a href="tel:02886922220" rel="nofollow">028-86922220</a>
                    </h4>
                </div>
            </div>
        </div>
        <div class="btns clearfix">
            <a href="https://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes" target="_blank" rel="nofollow"
               class="oline">在线咨询</a>
            <a href="javascript:;" class="edit" rel="nofollow">提交需求</a>
        </div>
    </div>
</div>
<div class="footer-content">
    <div class="weblg clearfix">
        <div class="friend-links">
            <h6 class="clearfix">
                <span class="tilte">友情链接</span>
                <a class="exchagne" href="http://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes">交换友情链接</a>
            </h6>
            <div class="link-list clearfix">
                <div class="link-slider">
                    <a href="https://www.cdxwcx.com/wangzhan/app.html" title="移动APP" target="_blank">移动APP</a><a href="http://www.scltwjx.com/
" title="公路打桩机" target="_blank">公路打桩机</a><a href="http://www.cdhuace.com/faguangzi/minifgz.html" title="迷你发光字" target="_blank">迷你发光字</a><a href="http://chengdu.kswjz.com/" title="成都网站建设" target="_blank">成都网站建设</a><a href="https://www.cdxwcx.com/wangzhan/mbshangcheng.html" title="电子商务商城网站" target="_blank">电子商务商城网站</a><a href="http://chengdu.cdcxhl.com/dingzhi/" title="定制网站建设" target="_blank">定制网站建设</a><a href="http://chengdu.cdcxhl.cn/dingzhi/
" title="定制网站设计" target="_blank">定制网站设计</a><a href="https://www.cdcxhl.com/quanwang.html" title="全网整合营销推广" target="_blank">全网整合营销推广</a><a href="https://www.cdcxhl.com/gaiban/chengdu.html" title="成都网站改版公司" target="_blank">成都网站改版公司</a><a href="http://chengdu.cdcxhl.com/xcx/" title="成都小程序" target="_blank">成都小程序</a>                </div>
            </div>
        </div>
    </div>
    <div class="full-foot-bottom">
        <div class="weblg clearfix">
            <p>成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询<a href="tel:028-86922220">028-86922220</a></p>
            <p>
                成都快上网科技有限公司-四川网站建设设计公司 | <a href="http://www.miitbeian.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a> Copyright 2020,ALL Rights Reserved cdkjz.cn | <a href="http://www.cdkjz.cn/" target="_blank">成都网站建设</a> | © Copyright 2020版权所有.</p>
            <p>专家团队为您提供<a href="http://www.cdkjz.cn/" target="_blank">成都网站建设</a>,<a href="http://www.cdkjz.cn/" target="_blank">成都网站设计</a>,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | <a href="###">网站建设地图</a></p>
        </div>
    </div>

</div>
<script type="text/javascript" src="../js/idangerous.swiper.min.js"></script>
<script type="text/javascript" src="../js/wow.min.js"></script>
<script type="text/javascript" src="../js/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="../js/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="../js/layout.js"></script>
</body>
</html>
<script>
    $(".singlepage 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>