如何在 twitter-bootstrap 中应用 navbar-inverse 的 CSS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12893846/
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 to apply the CSS of navbar-inverse in twitter-bootstrap
提问by Lorraine Bernard
By using twitter-bootstrapIt will be possible to modify the look of the navbar by adding .navbar-inverse.
通过使用twitter-bootstrap可以通过添加.navbar-inverse.
<div class="navbar navbar-inverse">
...
</div>
What I am trying to do is a simple js module to change the theme of the web site.
My script is just able to add a class to the body selector and then everything is made by the less file.
我想要做的是一个简单的 js 模块来改变网站的主题。
我的脚本只能向主体选择器添加一个类,然后所有内容都由 less 文件制作。
$('body').addClass('theme-dark');
By using js code it is quite easy to obtain the result.
通过使用js代码很容易得到结果。
$('.navbar').addClass('navbar-inverse');
But my question is different:
will it be possible just by adding the newTheme class to body selector to apply the navbar-inverse, changing the less file?
If yes how should I write the less rule?
但我的问题是不同的:
是否可以仅通过将 newTheme 类添加到 body 选择器来应用导航栏反转,更改较少的文件?
如果是,我应该如何编写 less 规则?
I would like to make something like this:
我想做这样的事情:
.theme-dark {
.navbar {
// a function which makes
// the style of navbar-inverse
Requirements:
要求:
I am using less for css, jquery and underscore.
我对 css、jquery 和下划线使用较少。
采纳答案by Liluakip
LESS provides the ability to use previously defined classes as mixins in other contexts. Try this:
LESS 提供了在其他上下文中使用先前定义的类作为混合的能力。试试这个:
.theme-dark {
.navbar {
.navbar-inverse;
}
}
回答by Jinu Joseph Daniel
.navbar div{ padding: 0.2em;} This solves the issue
.navbar div{ padding: 0.2em;} 这解决了这个问题

