简体   繁体   English

无论如何,是否可以针对不同的屏幕尺寸更改导航栏的字体颜色

[英]Is there anyway to change the font color of the navbar for different screen sizes

I'm using Bootstrap 3.0 and I want to change the color of my navigation menu for different screen sizes(eg red for iphone, black for tablet etc).I have tried doing this using media queries but have no luck so far. 我使用的是Bootstrap 3.0,我想更改导航菜单的颜色以适应不同的屏幕尺寸(例如,iPhone为红色,平板电脑为黑色等)。我尝试使用媒体查询来执行此操作,但到目前为止还算运气不好。

I have tried numerous methods: 我尝试了许多方法:

@media(max-width:480px) {
    .navbar-brand{
         position: absolute;
    top: 0;
    left: 0;
    width:170px;
    height:70px;

    }
    navbar-nav{
     color:#000000;      
}
    }


@media(max-width:480px) {
    .navbar-brand{
         position: absolute;
    top: 0;
    left: 0;
    width:170px;
    height:70px;

    }
    ul{
     color:#000000;      
}
    }

I 've tried assigning different id's still no luck.Can anyone help? 我尝试分配其他ID还是不走运。有人可以帮忙吗?

EDIT: Added http://www.bootply.com/nxQHGFqLED with whole CSS and the html part, maybe i missed something. 编辑:用整个CSS和html部分添加了http://www.bootply.com/nxQHGFqLED ,也许我错过了一些东西。

You are not doing it correctly. 您没有正确执行。 I see your code on Bootply, you are using max-width only. 我在Bootply上看到了您的代码,您仅在使用max-width。 For example, code in here @media(max-width:480px) {} will be overwritten by code in @media(max-width:767px) {} 例如,此处@media(max-width:480px){}中的代码将被@media(max-width:767px){}中的代码覆盖

Besides, you are giving ul.nav a {color:#b9b9b9 !important}, which is unnecessary, remove it! 此外,您正在给ul.nav一个{color:#b9b9b9!important},这是不必要的,将其删除! You should use !important to overwrite code if you really have to. 如果确实需要,您应该使用!important覆盖代码。 There are a lot of errors in the code you provided,please fix them first. 您提供的代码中有很多错误,请先解决。

Try something similar to the following - extend the html box to see it. 尝试类似以下内容的方法-扩展html框以查看它。

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

I used; 我用了;

@media(min-width: 720px) {
    .navbar-inverse .navbar-nav>li>a,
    .navbar-inverse .navbar-nav>.active>a,
    .navbar-inverse .navbar-brand
    {
        color: red;    
    }
}
@media(min-width: 920px) {
    .navbar-inverse .navbar-nav>li>a,
    .navbar-inverse .navbar-nav>.active>a,
    .navbar-inverse .navbar-brand
    {
        color: blue;    
    }
}

http://jsfiddle.net/7vyjX/1/ http://jsfiddle.net/7vyjX/1/

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

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