我正在尝试更改Visual Studio 2013中新的ASP.NET MVC 5应用程序附带的默认主题中的简单CSS属性。特别是我需要更改导航菜单的背景颜色。
我通过Firebug找到了这个属性,它的新值应该是:
.navbar-inverse { background-color: #5B80A5}
我最初尝试在Site.css
中添加覆盖CSS行,因为我注意到BundleConfig.cs
中的这些行:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
然而,导航菜单的背景颜色没有变化。
然后我在我的解决方案中搜索了.navbar-inverse
并返回了搜索结果:
Web\Content\bootstrap-theme.css(240):.navbar-inverse {
Web\Content\bootstrap-theme.css(249):.navbar-inverse .navbar-nav > .active > a {
Web\Content\bootstrap-theme.css(259):.navbar-inverse .navbar-brand,
Web\Content\bootstrap-theme.css(260):.navbar-inverse .navbar-nav > li > a {
Web\Content\bootstrap-theme.css.map(1):{"version":3,"file":"bootstrap-theme.css","sources":["less/theme.less","less/mixins/vendor-prefixes
Web\Content\bootstrap-theme.min.css(5): */.btn-default,.btn-primary,.btn-success,.btn-info,.btn-warning,.btn-danger{text-shadow:0 -1px 0 r
Web\Content\bootstrap.css(4190):.navbar-inverse {
Web\Content\bootstrap.css(4194):.navbar-inverse .navbar-brand {
Web\Content\bootstrap.css(4197):.navbar-inverse .navbar-brand:hover,
Web\Content\bootstrap.css(4198):.navbar-inverse .navbar-brand:focus {
Web\Content\bootstrap.css(4202):.navbar-inverse .navbar-text {
Web\Content\bootstrap.css(4205):.navbar-inverse .navbar-nav > li > a {
Web\Content\bootstrap.css(4208):.navbar-inverse .navbar-nav > li > a:hover,
Web\Content\bootstrap.css(4209):.navbar-inverse .navbar-nav > li > a:focus {
Web\Content\bootstrap.css(4213):.navbar-inverse .navbar-nav > .active > a,
Web\Content\bootstrap.css(4214):.navbar-inverse .navbar-nav > .active > a:hover,
Web\Content\bootstrap.css(4215):.navbar-inverse .navbar-nav > .active > a:focus {
Web\Content\bootstrap.css(4219):.navbar-inverse .navbar-nav > .disabled > a,
Web\Content\bootstrap.css(4220):.navbar-inverse .navbar-nav > .disabled > a:hover,
Web\Content\bootstrap.css(4221):.navbar-inverse .navbar-nav > .disabled > a:focus {
Web\Content\bootstrap.css(4225):.navbar-inverse .navbar-toggle {
Web\Content\bootstrap.css(4228):.navbar-inverse .navbar-toggle:hover,
Web\Content\bootstrap.css(4229):.navbar-inverse .navbar-toggle:focus {
Web\Content\bootstrap.css(4232):.navbar-inverse .navbar-toggle .icon-bar {
Web\Content\bootstrap.css(4235):.navbar-inverse .navbar-collapse,
Web\Content\bootstrap.css(4236):.navbar-inverse .navbar-form {
Web\Content\bootstrap.css(4239):.navbar-inverse .navbar-nav > .open > a,
Web\Content\bootstrap.css(4240):.navbar-inverse .navbar-nav > .open > a:hover,
Web\Content\bootstrap.css(4241):.navbar-inverse .navbar-nav > .open > a:focus {
Web\Content\bootstrap.css(4246): .navbar-inverse .navbar-nav .open .dropdown-menu > .dropdown-header {
Web\Content\bootstrap.css(4249): .navbar-inverse .navbar-nav .open .dropdown-menu .divider {
Web\Content\bootstrap.css(4252): .navbar-inverse .navbar-nav .open .dropdown-menu > li > a {
Web\Content\bootstrap.css(4255): .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:hover,
Web\Content\bootstrap.css(4256): .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:focus {
Web\Content\bootstrap.css(4260): .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a,
Web\Content\bootstrap.css(4261): .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:hover,
Web\Content\bootstrap.css(4262): .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:focus {
Web\Content\bootstrap.css(4266): .navbar-inverse .navbar-nav .open .dropdown-menu > .disabled > a,
Web\Content\bootstrap.css(4267): .navbar-inverse .navbar-nav .open .dropdown-menu > .disabled > a:hover,
Web\Content\bootstrap.css(4268): .navbar-inverse .navbar-nav .open .dropdown-menu > .disabled > a:focus {
Web\Content\bootstrap.css(4273):.navbar-inverse .navbar-link {
Web\Content\bootstrap.css(4276):.navbar-inverse .navbar-link:hover {
Web\Content\bootstrap.css(4279):.navbar-inverse .btn-link {
Web\Content\bootstrap.css(4282):.navbar-inverse .btn-link:hover,
Web\Content\bootstrap.css(4283):.navbar-inverse .btn-link:focus {
Web\Content\bootstrap.css(4286):.navbar-inverse .btn-link[disabled]:hover,
Web\Content\bootstrap.css(4287):fieldset[disabled] .navbar-inverse .btn-link:hover,
Web\Content\bootstrap.css(4288):.navbar-inverse .btn-link[disabled]:focus,
Web\Content\bootstrap.css(4289):fieldset[disabled] .navbar-inverse .btn-link:focus {
Web\Content\bootstrap.css(6207):.navbar-inverse { background-color: #F7931A}
Web\Content\bootstrap.css(6208):.navbar-inverse .navbar-nav>.active>a:hover,.navbar-inverse .navbar-nav>li>a:hover, .navbar-inverse .navba
Web\Content\bootstrap.css(6209):.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.open>a,.navbar-inverse .navbar-nav>.ope
Web\Content\bootstrap.css(6212):.navbar-inverse { background-image: none; }
Web\Content\bootstrap.css(6214):.navbar-inverse { border-color: #BD7014}
Web\Content\bootstrap.css(6215):.navbar-inverse .navbar-brand { color: #FFFFFF}
Web\Content\bootstrap.css(6216):.navbar-inverse .navbar-brand:hover { color: #9E601B}
Web\Content\bootstrap.css(6217):.navbar-inverse .navbar-nav>li>a { color: #FFFFFF}
Web\Content\bootstrap.css(6218):.navbar-inverse .navbar-nav>li>a:hover, .navbar-inverse .navbar-nav>li>a:focus { color: #FDFFF7}
Web\Content\bootstrap.css(6219):.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.open>a, .navbar-inverse .navbar-nav>.op
Web\Content\bootstrap.css(6220):.navbar-inverse .navbar-nav>.active>a:hover, .navbar-inverse .navbar-nav>.active>a:focus { color: #FFFFFF}
Web\Content\bootstrap.css(6223):.navbar-inverse .navbar-nav>.dropdown>a .caret { border-top-color: #FFFFFF}
Web\Content\bootstrap.css(6224):.navbar-inverse .navbar-nav>.dropdown>a:hover .caret { border-top-color: #FFFFFF}
Web\Content\bootstrap.css(6225):.navbar-inverse .navbar-nav>.dropdown>a .caret { border-bottom-color: #FFFFFF}
Web\Content\bootstrap.css(6226):.navbar-inverse .navbar-nav>.dropdown>a:hover .caret { border-bottom-color: #FFFFFF}
Web\Content\bootstrap.css.map(1):{"version":3,"file":"bootstrap.css","sources":["bootstrap.css","less/normalize.less","less/print.less","l
Web\Content\bootstrap.min.css(5): *//*! normalize.css v3.0.1 | MIT License | git.io/normalize */html{font-family:sans-serif;-webkit-text-s
我在每个上述文件的末尾添加了自定义CSS行,但仍然没有发生任何事情。我每次重建项目,清除浏览器中的缓存,但没有任何改变。
有关如何覆盖默认FPrap样式的任何想法吗?它让我疯了!
类似的问题并没有真正帮助:
Overriding bootstrap styles, How to override bootstrap input box style in table?, Cant override bootstrap
答案 0 :(得分:5)
文件名无效 - 请使用" Site.css"不是" site.css"。我也有这个问题,并且没有任何其他改变就这样解决了......
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/Site.css"));
答案 1 :(得分:1)
使您的自定义类包含.navbar-inverse
类的样式比bootstrap的类更具体。您可以在<body>
标记中添加一个类,并使用该类作为自定义替代的前缀。
.myCustomStyle .navbar-inverse
如果您无法编辑HTML,则可以使用每个html文档都有的明显标记:
body .navbar-inverse
还会使您的样式更具体,但对于代码可读性而言,请使用第一种方法。
您不必担心文件的放置位置,因为CSS特异性将始终覆盖bootstraps类+您始终可以确定它是您的类的名称前缀,使进一步调试更容易。
答案 2 :(得分:1)
如果将 CSS 引用放在引导程序之前,它将使自定义 CSS 优先于引导程序。如果你看我在 bootstrap.min.css 引用上面有 site.css 引用。这是在 Shared/_Layout.cshtml 文件中。
答案 3 :(得分:0)
删除bootstrap.min.css或bootstrap.css。 类似的问题在这里 CSS changes on MVC App not working