【发布时间】:2012-01-16 23:59:51
【问题描述】:
我的工作站上的高级开发人员代码如下:
table {border-collapse: collapse;border-spacing: 0;}
fieldset,img {border: 0;}
address,button,caption,cite,code,dfn,em,input,optgroup,option,select,strong,textarea,th,var {font:inherit;}
del,ins {text-decoration: none;}
li {list-style: none;}
caption,th {text-align: left;}
h1,h2,h3,h4,h5,h6 {font-size: 100%;font-weight: normal;}
q:before,q:after {content: '';}
abbr,acronym {border: 0;font-variant: normal;}
sup{vertical-align: baseline;}
sub{vertical-align: baseline;}
legend {color: #000;}
strong{font-weight:600;}
我编写了类似这样的代码(在高级开发人员审查/重写我的代码之前,我编写的同一 css 代码的不同部分):
html {
background-color: #7e1d32;
font: 16px/22px arial, sans-serif;
}
#outer_container {
min-height: 598px;
width: 100%;
background: #D4D4D4 url('../images/top_bg.gif') repeat-x top left;
}
#inner_container {
min-height: 698px;
width: 100%;
background: #D4D4D4 url('../images/top_designed_bg.jpg') repeat-x top center;
}
/* top orange banner */
#top_orange_bar {
height: 47px;
width: 100%;
background: transparent url('../images/top_orange_bg.gif') repeat top left;
}
#top_orange_bar_content {
width: 1026px;
margin: 0 auto;
}
#top_orange_bar_content .left {
float: left;
width: 730px;
margin-left: 40px;
}
#top_orange_bar_content .left h4 {
text-transform: uppercase;
letter-spacing: 1px;
font: bold 14px/52px arial, sans-serif;
color: #7f1e32;
}
#top_orange_bar_content .right {
float: right;
width: 160px;
margin-right: 40px;
text-align: right;
}
#top_orange_bar_content .right a {
margin-top: 8px;
}
像资深开发者那样写css代码有什么好处?
【问题讨论】:
-
不要把senior误认为better。
-
我会说你的代码比前辈的要好。您的 css 仅处理您真正想要更改的元素。高年级的可能会格式化非故意的元素。
-
@alex - 是的,但不要假设在这种情况下高级情况更糟,因为没有真正的性能理由来支持或反对长/短版本。两者都是有效的。如果其他程序员习惯了长格式,那么短的往往会令他们烦恼。在我工作的公司里,我们没有人像一本书一样通读 css。这一切都是通过搜索完成的,因此组织相对无关紧要。
-
@k_wave - 你确定他不只是指缩进和行使用吗?顶部的看起来像一个基本的 CSS 声明,以跟随重置。不一定是他应用相同的代码。
-
@KaiQing 如果“烦人”是指“难以阅读和维护”,那么是的 :)