在元素的类名中使用方括号的原因是什么? [英] What is the reason to have (square) brackets in an element's class name?

查看:282
本文介绍了在元素的类名中使用方括号的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对引导3模板中的class="[ col-xs-12 col-sm-offset-1 col-sm-5 ]"语句感到非常惊讶,我不确定

I was really surprised by this statement class="[ col-xs-12 col-sm-offset-1 col-sm-5 ]" in a bootstrap 3 template and I am not sure what is the difference between

class="[ col-xs-12 col-sm-offset-1 col-sm-5 ]"   

class="col-xs-12 col-sm-offset-1 col-sm-5"

能否请您详细介绍一下此括号的含义以及使用它们时的某些情况?

Can you please give me more details about the meaning of this brackets and some cases when they are used?

推荐答案

这无非是在视觉上分离类以进行分组.

This is nothing more other than visually separating classes with the intention of grouping them.

你们给的例子都做同样的事情.

The example you gave both do the same exact thing.

class属性中允许使用方括号,并且在技术上有效,只要方括号和类本身之间有空格即可.

The brackets are allowed in the class attribute and are technically valid so long as they have spaces between the bracket and the class itself.

有关此技术的其他信息,可以在 csswizardy中找到,为了后代,以下是摘录,解释了他的用法:

Additional information about this technique can be found on csswizardy, and for posterity, here is an excerpt explaining how he uses it:

工作方式

关于如何以及何时开始分组没有严格的规则 您的课程,但我为自己设定的准则是:

There is no hard and fast rule as to how and when to begin grouping your classes, but the guidelines I’ve set for myself are:

必须有一个以上的一组"课程.一个集合"必须包含 一个以上的班级.这基本上只是围观任何 需要它,例如:

There must be more than one ‘set’ of classes. One ‘set’ must contain more than one class. This basically just ringfences any groups that need it, for example:

<!-- Only one set. Nothing needs grouping. -->
<div class="foo  foo--bar">

<!-- Two sets, but only one class in each. Nothing needs grouping. -->
<div class="foo  bar">

<!-- Two sets, one of which contains more than one class. This set needs grouping. -->
<div class="[ foo  foo--bar ]  baz">

<!-- Two sets, both of which contain more than one class. These sets needs grouping. -->
<div class="[ foo  foo--bar ]  [ baz  baz--foo ]">

如何将它们分组 可以完全由您选择,这里的概念只涉及事实 我们将所有东西都分组了.

How you group them can be entirely your choice, the concept here just deals with the fact that we’re grouping things at all.

这篇关于在元素的类名中使用方括号的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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