【发布时间】:2017-04-19 03:23:52
【问题描述】:
在个人项目的网页上工作,并且对 HTML 中的内联样式或使用外部 CSS 文件的效率或当前标准有疑问。基本上,我将有几个不同的页面,其中包含一堆遵循这种模式的文本块:
下划线
粗体部分:一串正常字体粗细的数字
粗体部分:一串正常字体粗细的数字
等
粗体部分:一串正常字体粗细的数字
每个页面都会在页面上重复该类型的文本块 100-500 次。我想知道如果我用 HTML 为每个块设置样式,或者使用 CSS 是否会更好,是否有什么不同。即:
<u>Underline</u>
<b>Bold:</b> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
<b>Bold:</b> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
etc
对比
<style><!-- I'd use an external CSS file, but putting this in style tags to show what I'm thinking -->
div .underline { font-decoration: underline;
display: inline; }
div .bold { font-weight: bold;
display: inline; }
</style>
<body>
<div class="underline">Underline</u>
<div class="bold">Bold:</b> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
<div class="bold">Bold:</b> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
etc
</body>
这些方法中的任何一种是否比另一种更有效?我敢肯定,根据我的项目规模,这并不重要,但我很好奇,一遍又一遍地重复 b 和 u 标签还是使用 div 和 classes 会更好。这两种方法在世界上是否比另一种更普遍接受?谢谢!
【问题讨论】:
-
从长远来看,使用外部 CSS 文档会更好。尤其是随着项目规模越来越大。