HTML5& Bootstrap class =" container",它可以应用于body还是只有div? [英] HTML5 & Bootstrap class="container", can it be applied to body or only div?

查看:1017
本文介绍了HTML5& Bootstrap class =" container",它可以应用于body还是只有div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在讨论这个问题,每个人都在这里:
a)想要用div包装HTML5语义标签,而
b)想要将类选择器应用于div而不是语义标签。好像人们害怕出于某种原因将类打到语义标签上。

I keep bumping into this issue where everyone keeps: a) wanting to wrap HTML5 semantic tags with divs, and b) wants to apply class selectors to the divs and not the semantic tags. It's as if people are afraid of slapping classes onto semantic tags for some reason.

例如,我经常被告知这是不正确的,

For example, I am constantly told that this is "incorrect",

<body class="container">
    <header class="row">
        <div class="col-md-12"> ...

更喜欢这样的事情,

<body>
   <div class="container">
      <div class="row">
          <div class="col-md-12"> ...

这里,第一个例子我在h2标签中有列类

And here, where the first example I have the column class in the h2 tag

    <div class="row">
        <h2 class="col-4 feature">Featured Work</h2>
    </div>

但正确的方法是添加另一个div标签来应用该类,

But "the correct" way is to add yet another div tag to apply the class,

    <div class="row">
        <div class="col-4 feature">
            <h2>Featured Work</h2>
        </div>
    </div>

我知道这可能是基于意见的,但我发现在处理HTML5时,意见实际上很重要,因为几乎每个人都有问题,没有其他方法可以在没有意见的情况下敲定细节。

I understand that this might be opinion-based, but I have found that when dealing with HTML5, opinions actually matter since virtually everyone is having issues and there is no other way to hammer out the details without opinions.

推荐答案

我建议坚持到

<body>
   <div class="container">
      <div class="row">
          <div class="col-md-12"> ...

格式。

如果你打算与很多其他开发人员或使用bootstrap模板一起工作 - 你会看到容器类通常嵌套类div。

If you intend to work with a lot other developers or with bootstrap templates- you will see that the container classes typically nest row class divs.

由于我们讨论的是标记没有正确的答案,但强烈建议遵循此约定。

Since we are talking about markup there is no right answer, but following this convention is strongly recommended.


  1. 为了保持一致性

  2. 轻松更改样式&与其他项目的可重用性 - 这甚至打开了从其他项目或引导程序模板中直接替换css样式表的大门。 (我有一些令人惊讶的好结果)。

但是,如果你坚持给非div标签容器和col-X标签,是一致的。我不会推荐它,并会考虑遵循其自己的约定的任何模板作为代码质量差的指标。

However, if you insist on giving non-div tags "container" and "col-X" tags, be consistent. I wouldn't recommend it though and would consider any template that follows its own convention to be an indicator of poor code quality.

这篇关于HTML5&amp; Bootstrap class =&quot; container&quot;,它可以应用于body还是只有div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆