自动 HTML 生成指南,实现最大程度的 CSS 样式化
我想询问一下您在自动 HTML 生成方面的经验以及编码人员应该考虑什么才能达到最大的样式性?请添加良好的指南并解释其原因。
我将从 3 点开始:
您创建一个 div 或 td 或任何其他带有文本内容的内容..在其中添加一个跨度!
文本内容而不是
文本内容原因:有时您必须对文本内容应用不同的样式。如果您只能通过周围的 div 间接访问它,则有些事情是不可能的。
将 BR 放在 div 后面!
foo bar
;而不是
foo bar;原因:假设您决定让一些 div 向左浮动,您需要在它们之后清除向左。您现在可以使用
div#myId + br { 清除:左; }
如果您不需要 br,您可以简单地执行以下操作:
div#myId + br { 显示:无; }
如果没有附加 br,div 的浮动会很麻烦,并且您无法正确对齐内容。
这“应该”是显而易见的,但仍然是:使用类和 ID,以便您可以正确访问 CSS 中的每个项目。
好吧,这就是我发现的,现在轮到你扩展这组指南了:-)
I'd like to ask about your experience with automatic HTML generation and what should coders consider to reach a maximum stylability? Please add good guidelines and please explain the reason for them.
I'll start with 3 points:
You create a div or a td or anything else with text content.. Put a span in it!
<div><span>text content</span></div>
instead of
<div>text content</div>
Reason: Sometimes you have to apply a different styling to the text content. If you can only access it indirectly by the surrounding div some things aren't possible.
Put BRs behind divs!
<div id="myId">foo bar</div><br>
instead of
<div id="myId">foo bar</div>
Reason: Let's say you decide to let some divs float left, you'll need to clear left after them. You can do that now with
div#myId + br { clear: left; }
And if you don't need the br, you can simply do:
div#myId + br { display: none; }
Without that appended br the floating of divs is a real hassle and you can't properly align the content.
This 'should' be a no-brainer but still: Use classes and IDs, so that you can properly access every item in CSS.
Okay, that's what I found out, now it's your turn to extend this collection of guidelines :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第 1 点:如果 DIV 和 SPAN 都没有类或 ID,那么它们同样难以设计样式。我也绝不会为了 CSS 而添加额外的标记。我不会建议这种特殊的方法。
第2点:与上面相同。我鄙视在 HTML 中添加额外标记的系统。
第三点:是的。我绝对同意这一点。当然,说起来容易做起来难。
我不确定您正在创建哪种“自动生成系统”,但我们假设它是一个 CMS。因此,我建议如下:
CMS 不应该是一个设计管理系统。它应该管理内容。
CMS 不应该真正创建任何 HTML(除了内容本身的语义标记,例如段落、列表、块引用标签等)。 HTML 应由管理模板的人员创建。应该有页面模板、部分模板和内容模板……所有这些都可以由开发人员编辑。
例如,Wordpress 在这方面就做得很好。
point #1: if neither the DIV nor SPAN have a class or ID, then they are equally difficult to style. I'd never add extra markup for the sake of CSS, either. I wouldn't suggest this particular method.
point #2: Same as above. I despise systems that put extra markup in the HTML.
point #3: Yes. I definitely agree with that one. Granted, that's easier said than done.
I'm not sure what kind of 'automatic generation system' you are creating, but let's assume it's a CMS. As such, I'd recommend the following:
The CMS should not be a design management system. It should manage content.
The CMS should not really create any HTML (other than semantic markup of the content itself such a paragraph, list, blockquote tags, etc). The HTML should be created by someone managing the templates. There should be page templates, section templates, and content templates...all editable by a developer.
Wordpress does this well, for example.