简体   繁体   English

Bootstrap:是否可以将列类分配给标题标签

[英]Bootstrap: Is it OK to assign column classes to heading tags

Is it OK to do this?这样做可以吗?

<div class="row">
    <h3 class="col-md-12"> ... </h3>
    <div class="col-md-6"> ... </div>
    <div class="col-md-6"> ... </div>
</div>

I mean, is there any reason why assigning Bootstrap grid class to heading tags would be considered bad practice?我的意思是,是否有任何理由将 Bootstrap 网格类分配给标题标签会被认为是不好的做法? I can't think of any such reason, but I always see such classes used only for div's.我想不出任何这样的原因,但我总是看到这样的类只用于 div。

That's not a good idea.这不是一个好主意。 I'd do this instead:我会这样做:

<div class="row">
    <div class="col-md-12">
        <h3> ... </h3>
    </div>
    <div class="col-md-6"> ... </div>
    <div class="col-md-6"> ... </div>
</div>

The .col-*-* classes should be used only for layout purposes! .col-*-*类应该用于布局目的!

It is not a good idea because you are mixing layout and typography.这不是一个好主意,因为您正在混合布局和排版。

That said, with bootstrap 3.3.4, here is a comparison of the (direct) styles from both (h1 on the left and col-xs-12 on the right)也就是说,对于 bootstrap 3.3.4,这里是两者(左侧的 h1 和右侧的 col-xs-12)的(直接)样式的比较

比较

If you trace back and look at the ordering in the .css file, when they are different, while h1 properties trump the col (direct and inherited) properties in some cases, they don't mess up the ones that affect layout (margin, padding, float, display...) - these are either same or non-conflicting.如果您追溯并查看 .css 文件中的排序,当它们不同时,虽然 h1 属性在某些情况下胜过 col(直接和继承)属性,但它们不会混淆影响布局(边距、填充、浮动、显示...) - 这些是相同的或不冲突的。

So, practically, you wouldn't have any problems, but that could change with a different version of Bootstrap or if you override the standard styles.因此,实际上,您不会遇到任何问题,但可能会随着 Bootstrap 的不同版本或您覆盖标准样式而改变。

Its not good idea and practice这不是一个好主意和实践

every elements html tags should be inside a section ,that means we should use div and spans .div tag is used for defining a section of your document.每个元素 html 标签都应该在一个部分内,这意味着我们应该使用 div 和 spans .div 标签用于定义文档的一个部分。 With the div tag, you can group large sections of HTML elements together and format them with CSS.because div by default no property / Styles but other tags naturally have some styles.if you apply the classes for the div it reacts perfect but other tags we should overwrite styles then only reacts what we are expecting style.i hope clarify your doubt for your good practice plz go through it click here使用 div 标签,您可以将大部分 HTML 元素组合在一起并使用 CSS 对其进行格式化。因为默认情况下 div 没有属性/样式,但其他标签自然有一些样式。如果您为 div 应用类,它会做出完美的反应,但其他标签我们应该覆盖样式然后只对我们期望的样式做出反应。我希望能澄清您对良好实践的怀疑,请点击此处

Example例子

<div class="row">
    <div class="col-md-12">
        <h3> ... </h3>
    </div>
    <div class="col-md-6"> ... </div>
    <div class="col-md-6"> ... </div>
</div>

I would agree with it not being ideal.我同意它不理想。 Grid elements are for layout only and shouldn't be mixed with headings.网格元素仅用于布局,不应与标题混合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM