【问题标题】:replace nav bar with back ground color用背景颜色替换导航栏
【发布时间】:2013-03-04 22:16:22
【问题描述】:

我正在使用 twitter 引导程序开发响应式网站....
当我缩小浏览器窗口时,导航栏会折叠....
但在折叠的导航栏中,我需要显示背景颜色....
但它显示背景图像。如何将其替换为background-color: #14486b;
我不确定这个背景图像是从哪里出现的

<div class="nav-collapse in collapse" style="height: auto;">
            <ul class="nav">
              <li class="active"><a href="/docs/examples/product.html">Product</a></li>
              <li><a href="/docs/examples/solution.html">Solutions</a></li>
              <li><a href="/docs/examples/service.html">Services</a></li>
              <li class="iphonePartnerLink"><a href="/docs/examples/partner.html">Partners</a></li>
              <li class="iphoneContactLink"><a href="/docs/examples/contact.html">Contact</a></li>
            </ul>

            <ul class="nav" id="navSecond">
              <li class=""><a href="/docs/examples/partners.html">Partners</a></li>
              <li><a href="/docs/examples/contact.html">Contact</a></li>
            </ul>
            <form class="navbar-form pull-right">
              <input class="span2" type="text" placeholder="Email">
              <input class="span2" type="password" placeholder="Password">
              <button type="submit" class="btn">Sign in</button>
            </form>
          </div>

【问题讨论】:

标签: html css twitter-bootstrap


【解决方案1】:

尝试分析图像的来源。 这样做的好工具是 Firebug for Firefox https://addons.mozilla.org/de/firefox/addon/firebug/ 或者Chrome的开发工具(在Chrome中按F12打开)。在这两种工具中,您都可以检查 DOM 树的单个组件并查看所有附加的 CSS 样式(及其源代码)。

如果原因是背景图像,您可以通过以下方式覆盖样式:

#idOfComponent {
    background-image:none
}

【讨论】:

    【解决方案2】:

    您必须使用媒体查询将图像替换为背景颜色:

     @media (min-width: 768px) and (max-width: 979px) {
    
             .navbar-inner{
                     background-image: url("http://www.defie.co/designerImages/bg_bar.png");/*remove this */
                     background-color:#14486b;
                   }
    
               }
    
     /* Landscape phone to portrait tablet */
      @media (max-width: 767px) {
    
               .navbar-inner{
                     background-image: url("http://www.defie.co/designerImages/bg_bar.png");
                     background-color:#14486b;
                   }
            }
    
     /* Landscape phones and down */
      @media (max-width: 480px) {
    
                 .navbar-inner{
                     background-image: url("http://www.defie.co/designerImages/bg_bar.png");
                     background-color:#14486b;
                   }
            }
    

    如果你想修复顶部的导航栏:

    .navbar {
     left: 0;
     position: absolute;/*remove this line if you want to fix it */
     right: 0;
     top: 0;
      }
    

    评论后编辑:您已在媒体查询中将背景图像设置为无,并且颜色被注释掉,如下所示:

    @media (max-width:980px){
             .navbar-inverse .navbar-inner{
              background-image: none;
              /*background-color: red;*/
            }
           }
    @media (max-width: 767px) {
         .navbar-inverse .navbar-inner {
      background-image: none;
        /*background-color: red;*/
         }
        }
    
        @media (max-width: 480px) {
          .navbar-inverse .navbar-inner{
              background-image: none;
              /*background-color: red;*/
            }
          }
    

    请将样式替换为我上面提到的样式。

    【讨论】:

    • jsfiddle.net/rajkumart08/KNPZB/1/embedded/result 是的,它可以工作,但是应该有背景图像的主栏消失了......如何解决它......
    • 据我所知,您想用背景颜色代替 image 。你到底想要什么?
    • 当你缩小浏览器时,我想要带有背景图像的导航栏
    • Rajkumar 上述查询将帮助您在 iphone 平板电脑上获得带有背景图片的导航
    • jsfiddle.net/KNPZB/3/embedded/result 我在小提琴中更新了它不起作用
    猜你喜欢
    • 2020-08-12
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多