书写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://dcwzsj.com/article/iisdpo.html">http://dcwzsj.com/article/iisdpo.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/dchdeh.html">php大文件无法下载的解决方法-创新互联</a> </li><li> <a href="/article/dchogp.html">python使用ddt过程中遇到的问题怎么解决-创新互联</a> </li><li> <a href="/article/dchdij.html">elasticsearch启动时常见的错误集合-创新互联</a> </li><li> <a href="/article/dchdsg.html">Android开发实现Files文件读取解析功能示例-创新互联</a> </li><li> <a href="/article/dchdsi.html">CentOS中无线网卡的驱动安装与基本操作命令的操作方法-创新互联</a> </li> </ul> </div> </div> <div class="footer"> <div class="contain"> <div class="foot-nav clearfix"> <ul class="footer-menu"> <li class="dropdown" ><a class="dropdown-toggle">服务范围<b class="caret"></b></a> <ul class="child-menu"> <li><a href="/website.html">网站建设</a></li> <li><a href="/weixin/" rel="nofollow">微信开发</a></li> <li><a href="/app/" rel="nofollow">APP开发</a></li> <li><a href="/design/" rel="nofollow">品牌设计</a></li> <li><a href="/market/" rel="nofollow">营销推广</a></li> </ul> </li> <li class="dropdown"><a href="/webcase/" class="dropdown-toggle" title=德昌县做网站案例>德昌县做网站案例<b class="caret"></b></a> <ul class="child-menu"> <li><a href="/webcase/jtssgslist.html" id="ctl00_show_85" title="集团上市公司">集团上市公司</a></li> <li><a href="/webcase/ppwzlist.html" id="ctl01_show_81" title="品牌网站">品牌网站</a></li> <li><a href="/webcase/xiangyingshilist.html" id="ctl02_show_82" title="响应式网站">响应式网站</a></li> <li><a href="/Marketingwebsite/index.html" id="ctl03_show_83" title="营销型网站">营销型网站</a></li> <li><a href="/waimaowangzhan/index.html" id="ctl04_show_84" title="外贸网站">外贸网站</a></li> </ul> </li> <li class="dropdown"><a href="/news/" class="dropdown-toggle">新闻中心 <b class="caret"></b></a> <ul class="child-menu"> <li><a href="/news/2.html" id="ctl00_show_70" title="德昌县网站建设">德昌县网站建设</a></li><li><a href="/news/3.html" id="ctl00_show_70" title="德昌县网站设计">德昌县网站设计</a></li><li><a href="/news/5.html" id="ctl00_show_70" title="德昌县网站制作">德昌县网站制作</a></li><li><a href="/news/6.html" id="ctl00_show_70" title="德昌县网站优化">德昌县网站优化</a></li> </ul> </li> <li class="dropdown"><a href="/Knowledge/" class="dropdown-toggle">知识学堂 <b class="caret"></b></a> <ul class="child-menu"> <li><a href="/websitelist/8.html" title="德昌县网站建设知识">德昌县网站建设知识</a></li><li><a href="/websitelist/9.html" title="德昌县网站设计知识">德昌县网站设计知识</a></li><li><a href="/websitelist/10.html" title="德昌县微信营销知识">德昌县微信营销知识</a></li><li><a href="/websitelist/11.html" title="德昌县营销推广知识">德昌县营销推广知识</a></li> </ul> </li> <li class="dropdown"><a href="/about/" class="dropdown-toggle" rel="nofollow">关于我们 <b class="caret"></b></a> <ul class="child-menu"> <li><a href="/about/jj/index.html" id="ctl00_show_1300" title="公司简介" rel="nofollow">公司简介</a></li> <li><a href="/about/history/index.html" id="ctl01_show_1301" title="发展历史" rel="nofollow">发展历史</a></li> <li><a href="/about/jjtd/index.html" id="ctl02_show_1302" title="精英团队" rel="nofollow">精英团队</a></li> <li><a href="/about/join/" rel="nofollow">加入我们</a></li> <li><a href="/about/contact/" rel="nofollow">联系翔捷宏鑫</a></li> </ul> </li> </ul> <dl class="last-dl"> <dt> <a href="javascript:;" title="联系我们" rel="nofollow">联系翔捷宏鑫</a> </dt> <dd class="conta"> <span><img src="/Public/Home/images/zg_ewm.png" width="100" /><br /> 企业微信号</span> </dd> </dl> </div> <div class="childcompan clearfix"> </div> <div class="copy"> 友情链接: <a href="http://www.scqtclxh.com/" title="鑫友邦火锅桌" target="_blank">鑫友邦火锅桌</a> <a href="http://chengdu.cdcxhl.cn/seo/ " title="成都网站推广" target="_blank">成都网站推广</a> <a href="http://www.cdxwcx.cn/tuoguan/meishan.html" title="眉山主机托管" target="_blank">眉山主机托管</a> <a href="https://www.cdxwcx.com/wangzhan/mbshangcheng.html" title="模板商城网站" target="_blank">模板商城网站</a> <a href="http://www.zgfdjwx.com/" title="成都体系认证" target="_blank">成都体系认证</a> <a href="http://www.wjwzjz.com/" title="温江做网站公司" target="_blank">温江做网站公司</a> <a href="http://www.ynjbc.com/" title="企业网站维护公司" target="_blank">企业网站维护公司</a> <a href="http://www.tjjierui.cn/" title="什邡做网站" target="_blank">什邡做网站</a> <a href="http://www.scpingwu.com/" title="四川平武网站建设" target="_blank">四川平武网站建设</a> <a href="http://www.njwzjz.com/" title="njwzjz.com" target="_blank">njwzjz.com</a> </div> <br> 123ABC<strong> <a href="/">德昌县网站建设</a></strong>,德昌县定制网站建设——全心全意建网站公司 </div> </div> <script type="text/javascript" src="/Public/Home/js/meiqia.js"></script> <script type="text/javascript" src="/Public/Home/js/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="/Public/Home/js/jquery.easing.1.3.js"></script> <script type="text/javascript" src="/Public/Home/js/i.js"></script> <script type="text/javascript" src="/Public/Home/js/script.js"></script> <script type="text/javascript" src="/Public/Home/js/SuperSlide.js"></script> <script type="text/javascript" src="/Public/Home/js/jquery.toTop.min.js"></script> <script type="text/javascript" src="/Public/Home/js/num-change.js"></script> <script type="text/javascript" src="/Public/Home/js/jquery.nicescroll.min.js"></script> <script type="text/javascript"> $(".menu li").eq(7).addClass("current-menu-item"); </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>