[英]Different CSS Styles
/* Style 1 */
.myclass {
background:#ff0;
border:1px solid #ff0
}
#myid {
width:80px;
height:80px;
}
/* Style 2 */
.myclass { background:#ff0; border:1px solid #ff0 }
#myid { width:80px; height:80px; }
I'm sure there must be more styles for writing CSS, I'd like to know what are they. 我确定必须有更多的样式来编写CSS,我想知道它们是什么。 Is there an article already written that lists all styles.
是否已经有一篇文章列出了所有样式。
Thanks 谢谢
Here is a good list and discussion: 这是一个很好的清单和讨论:
http://css-tricks.com/different-ways-to-format-css/ http://css-tricks.com/different-ways-to-format-css/
My answer will be more than you want, because I've seen a css files that was 60K long and consisted mostly of classes and ID's overwriting others - because no one knows how css works. 我的答案将超出您的期望,因为我看到了一个css文件,该文件长60K,并且主要由类和ID覆盖其他文件组成-因为没人知道css的工作方式。 They just keep adding things until they get the result they want.
他们只是不断添加东西,直到获得想要的结果。
.myClass { /* 0,0,1,0 */
top-margin: 1px;
padding: 3px;
}
#myid { /* 0,1,0,0 */
width: 80px;
height: 80px;
}
Repeat with space in between. 在两者之间重复空格。
Now the important stuff. 现在重要的东西。
.table
. .table
。 If you need a new table class at www.example.com/foo/... it should be named something like .foo-table
and should apply and be used by things .foo-table
类的东西,并应被事物使用并使用 I'm the only one I know that does it this way, but everyone who has used it since has said, "Damn, that makes it easy to find my CSS errors!" 我是唯一知道这样做的人,但是此后使用过它的每个人都说:“该死,这很容易找到我的CSS错误!”
Ok. 好。 I don't know if there is any article discuss about this.
我不知道是否有任何文章对此进行讨论。 But for me style 1 is better in term of readability and debugging.
但是对我来说,样式1在可读性和调试方面更好。
just my 2 cent 只有我的2美分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.