什么是最好的HTML布局技术? DIV与表格
我发现使用表格作为主干更容易操作,特别是在垂直对齐时。但我似乎只是在使用带有大量CSS的DIV时找到代码示例,这些代码看起来像是CSS的内部工作方式。
I find using tables as the backbone easier to manipulate, specially when aligning things vertically. But I only seem to find code samples using DIV with heaps of CSS that looks like hacks into the inner workings of CSS.
使用< table>
进行布局被视为黑客攻击。
Using <table>
for layout is considered a hack.
布局用于很久以前在CSS出现之前用< table>
来完成。如今,通常的做法是将项目的结构,样式和行为分别分为 HTML,CSS和JavaScript 。
Layouts used to be done with <table>
a long time ago before CSS was around. Nowadays, it common practice to separate out the structure, styling, and behavior of your project into HTML, CSS, and JavaScript, respectively.
使用HTML5,推动使用语义标签,例如< article>
,< section>
,依此类推< div>
。尽管如此,< div>
仍然没问题,比< table>
优先100%,除非你专门工作使用表格数据。即使这样,实际的布局样式仍应在CSS中进行。
With HTML5, there has been a push for using semantic tags such as <article>
, <section>
, and so on in place of <div>
. Nonetheless, <div>
is still fine and 100% preferable over <table>
unless you're specifically working with tabular data. Even then, the actual layout styling should still take place in your CSS.