Html Bootstrap 和 html5 - section 还是 div?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22298890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap and html5 - section or div?
提问by oneday
I have a question regarding using Bootstrap - I see that on default they use a lot of DIVs instead of sections etc.
我有一个关于使用 Bootstrap 的问题 - 我看到默认情况下他们使用很多 DIV 而不是部分等。
I've been reading the HTML5 specification lately - when to use section and when to use div. The basic idea is that DIVs should be used only if any specific HTML5 element doesn't apply.
我最近一直在阅读 HTML5 规范 - 何时使用 section 以及何时使用 div。基本思想是,仅当任何特定的 HTML5 元素不适用时才应使用 DIV。
Now, if I want to create an HTML5 website using Bootstrap, should I change the DIVs to specific HTML elements (for example SECTION)?
现在,如果我想使用 Bootstrap 创建一个 HTML5 网站,我是否应该将 DIV 更改为特定的 HTML 元素(例如 SECTION)?
回答by Cirou
It really depends on your page's content but basically you could use HTML5 tags and apply bootstrap classes like this:
这实际上取决于您页面的内容,但基本上您可以使用 HTML5 标签并应用如下引导程序类:
<section class="row">
...
</section>
<footer class="row">
...
</footer>
But as said it depends on your content, and even more, you're not forced to use <section>
tags, they have the specific purpose to represents a generic document or application section, and they're not mandatory.
但如前所述,这取决于您的内容,更重要的是,您不会被迫使用<section>
标签,它们具有表示通用文档或应用程序部分的特定目的,并且它们不是强制性的。
The <div>
tags are generic tag usually used for styling, as in bootstrap. But if you want to keep the <section>
tags, maybe you could prefer a mixed solution like this:
该<div>
标签是通用的标签通常用于造型,如引导。但是如果你想保留<section>
标签,也许你更喜欢这样的混合解决方案:
<section>
<div class="row">
...
</div>
<div class="row">
...
</div>
</section>
With this solution the <section>
tag is used for grouping contents, as it should be, and the <div>
tags for styling it.
使用此解决方案,<section>
标签用于对内容进行分组,正如它应该的那样,以及<div>
用于样式化的标签。
回答by Iqbal
Section
is not for design purpose, it has specific meaning. It indicates separate sections/parts of a web page. On the other hand, div
has no specific meaning. You can use div
s anonymously for managing your front-end styles.
Section
不是为了设计目的,它有特定的含义。它表示网页的单独部分/部分。另一方面,div
没有特定的含义。您可以div
匿名使用s 来管理您的前端样式。
回答by Jen
As far as I've read using section is correct semantics and helps with SEO.
据我阅读使用部分是正确的语义并有助于搜索引擎优化。
回答by Aijay Iphie
Section tags are used to segment your web pages and makes it SEO optimized while divs are used for styling your contents.
部分标签用于分割您的网页并使其 SEO 优化,而 div 用于设置您的内容样式。