在元素的类名中使用方括号的原因是什么?

编程入门 行业动态 更新时间:2024-10-10 07:27:43
本文介绍了在元素的类名中使用方括号的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对引导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.

更多推荐

在元素的类名中使用方括号的原因是什么?

本文发布于:2023-11-27 22:42:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方括号   元素   原因   类名中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!