Bootstrap and html5 - section or div?

2020-05-21 09:05发布

I have a question regarding using Bootstrap - I see that on default they use a lot of DIVs instead of sections etc.

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.

Now, if I want to create an HTML5 website using Bootstrap, should I change the DIVs to specific HTML elements (for example SECTION)?

4条回答
够拽才男人
2楼-- · 2020-05-21 09:29

Section tags are used to segment your web pages and makes it SEO optimized while divs are used for styling your contents.

查看更多
孤傲高冷的网名
3楼-- · 2020-05-21 09:35

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 divs anonymously for managing your front-end styles.

查看更多
手持菜刀,她持情操
4楼-- · 2020-05-21 09:45

It really depends on your page's content but basically you could use HTML5 tags and apply bootstrap classes like this:

<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.

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:

<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.

查看更多
▲ chillily
5楼-- · 2020-05-21 09:51

As far as I've read using section is correct semantics and helps with SEO.

查看更多
登录 后发表回答