Bootstrap导航栏链接文本在Google Chrome中分解,但不在Firefox中 [英] Bootstrap navbar link text breaks down in google chrome but not in firefox

查看:148
本文介绍了Bootstrap导航栏链接文本在Google Chrome中分解,但不在Firefox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个navbar在bootstrap设置,它工作正常在firefox,但我google chrome。导航链接文本,多个词像联系我们的第二个单词下来。我如何解决这个问题,它在莫西娅奇怪,即使窗口被调整大小的词不打破 < img src =https://i.stack.imgur.com/V2Tdw.pngalt =问题的截图>

I have a navbar in bootstrap setup, it works fine in firefox but i google chrome. The nav links text which as multiple words like 'contact us' the second word goes down. How do I fix this problem, its weird in mozilla even when window is resized the word does not break

HTML

<nav class="navbar navbar-default">
            <div class="container-fluid">

            <div class="navbar-header">
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
            </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">

            <li class="active nav-links"><a href="#">Home<span class="sr-only">(current)</span></a></li>
            <li class="nav-links"> <a href="aboutus.html">About Us</a> </li>
            <li class="nav-links"> <a href="whoweare.html">Who We Are</a> </li>
            <li class="nav-links"> <a href="mission.html">Mission</a> </li>
            <li class="nav-links"> <a href="activities.html">Activities</a> </li>
            <li class="nav-links"> <a href="gallery.html">Gallery</a> </li>
            <li class="nav-links"> <a href="donate.html">Donate</a> </li>
            <li class="nav-links"> <a href="sitemap.html">Sitemap</a> </li>
            <li class="nav-links"> <a href="contactus.html">Contact Us</a> </li>

          </ul>


        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
    </nav>

CSS

 nav {
                width: 100%;
                height: 40px;
                background: -webkit-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
                background: -o-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
                background: linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
                border-radius: 6px !important;
                -moz-border-radius: 6px !important;
                color: white
            }

        .navbar .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a {
            color: white;  /*Sets the text hover color on navbar*/
            padding-right: 22%;
            font-size: 1.2em;
        }


        .navbar .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
            color: white;  /*Sets the text hover color on navbar*/
            text-decoration: underline;
        }

        .navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active >   
         a:hover, .navbar-default .navbar-nav > .active > a:focus {
            background: none;
            color: white;
            text-decoration: underline;
        }


推荐答案

$ c> white-space:nowrap; 以防止文本换行,您可能需要使用以下内容:

You can use white-space: nowrap; to prevent text wrapping and you may want to use the following:

1)需要重置导航栏的高度。
2)您可以使用媒体查询更改填充,以便您的链接不会在视口缩小时换行。

1) You don't need to reset the height of your navbar. 2) You can use a media query to change the padding so your links won't wrap to a new line as the viewport is reduced

请参阅示例代码段。

.navbar.navbar-default {
  width: 100%;
  background: -webkit-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
  background: -o-linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
  background: linear-gradient(#3f9a15, #388813, #3f9a15, #388813, #3f9a15);
  border-radius: 6px !important;
  -moz-border-radius: 6px !important;
  color: white
}
.navbar.navbar-default .navbar-nav > li > a:hover,
.navbar.navbar-default .navbar-nav > li > a {
  color: white;
  /*Sets the text hover color on navbar*/
  font-size: 1.2em;
}
.navbar.navbar-default .navbar-nav > li > a:hover,
.navbar.navbar-default .navbar-nav > li > a:focus {
  color: white;
  /*Sets the text hover color on navbar*/
  text-decoration: underline;
}
.navbar.navbar-default .navbar-nav > .active > a,
.navbar.navbar-default .navbar-nav > .active > a:hover,
.navbar.navbar-default .navbar-nav > .active > a:focus {
  background: none;
  color: white;
  text-decoration: underline;
}
@media (max-width: 992px) and (min-width: 768px) {
  .navbar.navbar-default .navbar-nav > li > a {
    padding-left: 5px;
    padding-right: 5px;
    white-space: nowrap;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>

      </button>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home<span class="sr-only">(current)</span></a>

        </li>
        <li> <a href="aboutus.html">About Us</a> 
        </li>
        <li> <a href="whoweare.html">Who We Are</a> 
        </li>
        <li> <a href="mission.html">Mission</a> 
        </li>
        <li> <a href="activities.html">Activities</a> 
        </li>
        <li> <a href="gallery.html">Gallery</a> 
        </li>
        <li> <a href="donate.html">Donate</a> 
        </li>
        <li> <a href="sitemap.html">Sitemap</a> 
        </li>
        <li> <a href="contactus.html">Contact Us</a> 
        </li>
      </ul>
    </div>
  </div>
  <!-- /.container-fluid -->
</nav>

这篇关于Bootstrap导航栏链接文本在Google Chrome中分解,但不在Firefox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆