一个 div 可以有多个类吗(Twitter Bootstrap) [英] Can a div have multiple classes (Twitter Bootstrap)

查看:29
本文介绍了一个 div 可以有多个类吗(Twitter Bootstrap)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个 div 标签可以有两个类吗?

我正在使用 twitter bootstrap,并且有两个我想使用的预定义类.

一个是 active 类,我想在导航栏中的 dropdown-toggle 上使用.

在不覆盖 css 的情况下,在 html 中处理此问题的最佳方法是什么.

解决方案

当然,一个 div 可以拥有任意数量的类(这通常与引导程序和 HTML 相关):

只需按空格分隔类即可.

另外:请记住,一些引导类应该用于相同的东西,但在不同的情况下(例如 对齐类,你可能想要一些左对齐、右对齐居中的东西,但它必须只有一个 )并且你不应该一起使用它们,否则你会得到一个意想不到的结果,基本上会发生的是 specificity 将是应用的(或者如果它们相同,那么它将是最后在 CSS 上定义的那个).所以你最好避免做这样的事情:

<p class="text-center text-left">一些文字</p>

Can a div tag have two classes?

I am using twitter bootstrap, and there are two predefined classes that I would like to use.

One is an active class that I would like to use on a dropdown-toggle within a nav bar.

What is the best way of approaching this in the html, with out overriding the css.

解决方案

Sure, a div can have as many classes as you want (this is both regarding to bootstrap and HTML in general):

<div class="active dropdown-toggle"></div>

Just separate the classes by space.

Also: Keep in mind some bootstrap classes are supposed to be used for the same stuff but in different cases (for example alignment classes, you might want something aligned left, right or center, but it has to be only one of them) and you shouldn't use them together, or you'd get an unexpected result, basically what will happen is that the class with the highest specificity will be the one applied (or if they have the same then it'll be the one that's defined last on the CSS). So you better avoid doing stuff like this:

<p class="text-center text-left">Some text</p>

这篇关于一个 div 可以有多个类吗(Twitter Bootstrap)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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