nettuts带来的5个css书写技巧,简单翻译一下它的中心思想。
你也许需要先了解什么是css重置。然后怎么样写css重置呢。
不按字母顺序排的
div#header h1 {z-index: 101;color: #000;position: relative;line-height: 24px;margin-right: 48px;border-bottom: 1px solid #dedede;font-size: 18px;}
按字母顺序排的
div#header h1 { border-bottom: 1px solid #dedede; color: #000; font-size: 18px; line-height: 24px; margin-right: 48px; position: relative; z-index: 101;}
理由是这样可以更好的找到某个属性。个人觉得还好,差别也不是太大。不过也许会适合你。
使用css注释来分给css分组,这样结构明了,也有利于协同设计。
/*****reset*****/xxxxxxx{xxxxx}xxxxx{xxxxx}/*****layouts*****/xxxxxxx{xxxxx}xxxxx{xxxxx}
不要无意义的去讨论到底一个选择器的所有属性写在一行,还是每个属性写一行比较好。你自己觉得ok就好。
iv#header { float: left; width: 100%; }div#header div.column {border-right: 1px solid #ccc;float: rightright;margin-right: 50px;padding: 10px;width: 300px;}div#header h1 { float: left; position: relative; width: 250px; }
比如我个人就喜欢写在一行,因为每排写一行会让整个文档感觉太长了,找起来不方便。如果你喜欢写一行,但是发给team的另一个,他却喜欢每排一行,那怎么办?其实很简单,把css拿去w3c验证,它会有一份结果,会自动转换成每排一行。
这个我没有太看懂。大概理解是对html的标记弄好后再写css会比较不容易出错。比如我写一个页面,先写一个最基本的标记结构
<body> <div id="wrapper"> <div id="header"><!--end #header--> <div id="container"> <div id="content"> </div><!--end #content--> <div id="sidebar">
</div>
<!--end #sidebarr--> </div><!--end #container--> <div id="footer"> <
/div>
!<--end #footer-->
</div>
<!--end #wrapper--></body>
然后就是尽量善用子选择器,而不是一要给哪个元素进行样式化,就给它添加个选择器。
新闻热点
疑难解答