twitter-bootstrap 如何扩展引导类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17348482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How extend bootstrap classes
提问by ramiromd
I am doing my first steps with Bootstrap Twitter, and need to extend components. For example, I would like to change the navbar background, but without changing the original css file.
我正在使用 Bootstrap Twitter 做我的第一步,并且需要扩展组件。例如,我想更改导航栏背景,但不更改原始 css 文件。
I tried to create a new class .testwith the new background:
我尝试.test使用新背景创建一个新类:
.test{
background-color: red !important;
}
And I've invoked it in the hmtl as:
我在 hmtl 中调用了它:
<div class="navbar navbar-fixed-top test">
But, it doesn't work. How can do this?
但是,它不起作用。怎么能做到这一点?
采纳答案by Zim
There are a few ways to customize/extend Bootstrap classes which are all discussed here: Twitter Bootstrap Customization Best Practices
有几种方法可以自定义/扩展 Bootstrap 类,这些方法都在这里讨论:Twitter Bootstrap 自定义最佳实践
If you intend to override the boostrap styles with your own custom CSS you should avoid using !importantas this is generally a bad practice.
如果您打算使用自己的自定义 CSS 覆盖 boostrap 样式,则应避免使用,!important因为这通常是一种不好的做法。
In the case of the navbar, the element that has the background-color is navbar-innerso you'd want to override like this:
在 的情况下navbar,具有背景颜色的元素是navbar-inner这样的,您希望像这样覆盖:
.test .navbar-inner{
background-color: red;
}
Custom navbar example: http://bootply.com/61032
自定义导航栏示例:http: //bootply.com/61032

