简体   繁体   English

如何使 twitter-bootstrap 导航栏没有颜色

[英]How to make twitter-bootstrap navbar have no color

I'm trying to reproduce a effect like basecamp navbar in my app.我正在尝试在我的应用程序中重现像 basecamp 导航栏这样的效果。

The deal is that the navbar would have the same color as body background color, and no borders or anything, wich made the feel that 'is all the same thing'....交易是导航栏将具有与正文背景颜色相同的颜色,并且没有边框或任何东西,这让人感觉“都是一样的东西”......

Anybody know a good way of doing this?有人知道这样做的好方法吗? PS: I'm using the .less files, so, I can easily edit the variables. PS:我正在使用.less文件,因此,我可以轻松编辑变量。

Thanks in advance提前致谢


EDIT: I forget to said, but I want the fixed-top and responsiveness behaviors of bootstrap too.. I also already using tw bootstrap in my app, so, I'll really want to use it.编辑:我忘了说,但我也想要 bootstrap 的固定顶部和响应行为。我也已经在我的应用程序中使用了 tw bootstrap,所以,我真的很想使用它。

Ahem, this is easily done with pure CSS, you don't even need Bootstrap for this, neither its CSS classes咳咳,这很容易用纯 CSS 完成,你甚至不需要 Bootstrap,也不需要它的 CSS 类

HTML: HTML:

    <ul class="navigation">
      <li><a href="#">Home</a></li>
      <li><a href="#">Link</a></li>
      <li><a href="#">Link</a></li>
    </ul>

CSS: CSS:

​.navigation li {
    display: inline;
    padding-left: 5px;
    padding-right: 5px;
}

Of course, you still have to style the links to remove text-decoration etc.当然,您仍然需要设置链接样式以删除文本装饰等。

Edit:编辑:

.navbar-inner {
  background: none !important; 
  border: 0 !important;
  box-shadow: none !important;
  -webkit-box-shadow: none !important;
}

.navbar-inverse .nav .active > a {
  background: 0 !important; 
  color: #333 !important;
  box-shadow: none !important;
  -webkit-box-shadow: none !important;
}

.navbar-inverse .nav > li > a {
  color: #333 !important;
  text-shadow: none !important;
}

.navbar-inverse .nav > li > a:hover {
  color: #333 !important;
}

Demo : http://codepen.io/anon/pen/vJsfz演示: http : //codepen.io/anon/pen/vJsfz

I've just made some simple "reset" lines with CSS to remove every color, borders and shadows (at least for Webkit browsers).我刚刚使用 CSS 制作了一些简单的“重置”行来移除所有颜色、边框和阴影(至少对于 Webkit 浏览器而言)。 Maybe you have to modify it a bit more.也许你需要再修改一下。

/*  clear bootstrap header colors */
.navbar-default {
    background-color: white;
    border-color: white;
}

Maybe I'm not understanding something but having just dealt with this, it seems like the easiest thing to do is override the default navbar color with a completely transparent color in the alpha channel...也许我不明白什么,但刚刚处理过这个问题,似乎最简单的方法是在 alpha 通道中用完全透明的颜色覆盖默认导航栏颜色......

.navbar-default {
    background: rgba(255, 255, 255, 0);
}

If using rgba, the first three numbers represent red, green, blue, on a scale of 0-255, and the last is the alpha channel, 0 being completely transparent and 1 being completely opaque.如果使用 rgba,前三个数字代表红、绿、蓝,范围为 0-255,最后一个是 alpha 通道,0 表示完全透明,1 表示完全不透明。

Setting it to white would work, too, if your background happened to be white, but this way it doesn't matter what your background is.如果您的背景恰好是白色,则将其设置为白色也可以,但这样您的背景就无关紧要了。

Bootstrap (v5 beta, but will also apply to some previous versions) will mark certain styling classes with an !important tag. Bootstrap(v5 beta,但也适用于某些以前的版本)将使用!important标记标记某些样式类。 This will override standard specificity rules when applying css.这将在应用 css 时覆盖标准特异性规则。 If you navigate to your page in Chrome and use the dev-tools to highlight the element you want to change you can see what styles are being applied.如果您在 Chrome 中导航到您的页面并使用开发工具突出显示您想要更改的元素,您可以看到正在应用哪些样式。 In the case of the navbar , Bootstrap defines the default background color using a class of .bg-light .navbar的情况下,Bootstrap 使用.bg-light类定义默认背景颜色。 In dev-tools you can see that .bg-light styling is as follows:在 dev-tools 中可以看到.bg-light样式如下:

.bg-light {
    background-color: #f8f9fa!important;
}

In order to override the !important tag at the end of that property, you need to include a !important tag of your own to your local css file.为了覆盖该属性末尾的!important标记,您需要在本地 css 文件中包含一个您自己的!important标记。 Do not make this change to the existing class of .bg-light as it could break other Bootstrap elements in your code.不要对现有的.bg-light类进行此更改,因为它可能会破坏代码中的其他 Bootstrap 元素。 Instead, the way I handle this, is to assign an id to that element in my HTML and then set a custom css property to override it using and !important tag.相反,我处理这个问题的方法是在我的 HTML 中为该元素分配一个id ,然后设置一个自定义 css 属性以使用!important标签覆盖它。 Ex:前任:
HTML HTML

<nav class="navbar navbar-expand-lg navbar-light bg-light" id="navbar">

CSS CSS

#navbar {
    background-color: transparent!important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM