css–sprit
Nothing makes me cringe more than when I see other programmers use a class declaration for every XHTML tag in their programming. Using too many CSS class declarations can result in:
当我看到其他程序员在其编程中的每个XHTML标记中使用类声明时,没有什么比让我更畏缩的了。 使用过多CSS类声明可能会导致:
- Bloated page downloads for the user 用户的膨胀页面下载
- Bloated CSS file downloads for the user 用户的膨胀CSS文件下载
- Difficulty in editing CSS files due to so many classes for the programmer 由于程序员需要太多的类,因此难以编辑CSS文件
- Using meaningless class names to try to save space 使用无意义的类名尝试节省空间
There's a more efficient way to code your pages without using a lot of classes: use formatting tags. A CSS purist would say that all formatting should take place in the CSS file, so we'll have that covered. Also, we'll put to use some tags that we probably wouldn't use otherwise.
有一种无需使用很多类即可对页面进行编码的更有效方法:使用格式标记。 一个CSS纯粹主义者会说所有格式都应该在CSS文件中进行,因此我们将对此进行介绍。 另外,我们将使用一些我们可能不会使用的标签。
代码 (The Code)
Here's the CSS code I'll use:
这是我将使用CSS代码:
strong, font, em, big, small, i { display:block; font-weight:normal; font-style:normal; margin:0; padding:5px; font-size:11px; }strong { width:700px; margin:10px auto; }font { height:100px; background:pink; }em { width:150px; height:300px; float:left; background:lightblue; }big { width:400px; height:300px; float:left; background:lightgreen; }small { width:120px; height:300px; float:left; background:lightyellow; }i { background:#fffea1; height:100px; clear:both; }
Here's the XHTML structure I'll use withing the page:
这是我将在页面中使用的XHTML结构:
{ This is the header } { This is the navigation bar } { This is the content pane } { This is the sidebar } { This is the footer }
问题 (The Issues)
While the above works, many would argue that the above is bad practice because:
尽管上述方法有效,但许多人认为上述做法是错误的做法,因为:
- It may bring page validation issues 它可能会带来页面验证问题
- Code may be more difficult to maintain because the programmer wouldn't remember how he/she is using each tag 代码可能更难以维护,因为程序员将不记得他/她如何使用每个标签
- Some programmers may prefer using formatting tags for formatting. 一些程序员可能更喜欢使用格式化标签进行格式化。
I would have no issue using the code above. The worst issue I can identify from the list is that the page may not validate, but page validation often isn't necessary as long as the page functions as it should.
使用上面的代码,我不会有任何问题。 我可以从列表中识别出的最糟糕的问题是页面可能无法验证,但是只要页面能够正常运行,通常就不需要页面验证。
What are your thoughts? Have you ever used this type of formatting? Do you take issue with the above code?
你觉得呢?你有没有什么想法? 您曾经使用过这种格式吗? 您是否对上述代码有疑问?
翻译自:
css–sprit