简体   繁体   中英

bootstrap navbar elements too much in the center

I'm using bootstrap to build a navbar for my page, but am finding that the elements are too bunched towards the center, leaving a lot of extra space to the sides. Is there a way to extend these more to take advantage of the extra width of the page?

在此输入图像描述

Here is my HTML/CSS. Basically took Example 6 from https://codepen.io/bootstrapped/pen/KwYGwq?editors=1100

HTML:

  <nav class="navbar navbar-inverse navbar-fixed-top example6">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar6">
          <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 text-hide" href="/fedhr/Fed_Splash_New.do"/>
      </div>
      <div id="navbar6" class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li><a href="/fedhr/Fed_Splash_New.do"><span class="glyphicon glyphicon-home"></span></a></li>

          <li><a href="#Profile"><span class="glyphicon glyphicon-user"></span>$[SP] <g:no_escape>${jvar_user_name}</g:no_escape> <g:no_escape>${jvar_user_lastname}</g:no_escape></a></li>
          <li><a href="#Tasks"><span class="glyphicon glyphicon-list-alt"></span>$[SP] Tasks</a></li>
          <li><a href="#About"><span class="glyphicon glyphicon-plane"></span>$[SP] About Us</a></li>
          <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-phone-alt"></span>$[SP] Contact Us <span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">
              <li><a href="mailto:someone@example.com?Subject=Hello%20again">Email Us</a></li>
              <li><a href="/$chat_support.do?queueID=cd846e1747a102009eaff6df1d9a7175" target="_blank">Chat with HR</a></li>
            </ul>
          </li>
            <li><a href="../logout.do"><span class="glyphicon glyphicon-log-out"></span>$[SP] Logout</a></li>
        </ul>
      </div>
     </div>
  </nav>

CSS:

.example6 .navbar-brand{ 
  background: url(#) center / contain no-repeat;
  width: 200px;
}

You can use the property margin-right inside the the .navbar-right class. But be aware that your <ul> will overflow the container parent class.

.navbar-right {
    float: right!important;
    margin-right: -20px;
}

the <div class="container"> sets the width of the content inside to a fixed width that depends on the viewport width (see http://getbootstrap.com/css/#overview-container ) . To let the content stretch to the full available width, change it into <div class="container-fluid">

Use <div class="container-fluid"> , not <div class="container"> .

This way it will adapt to the available width of the viewport.

More on: Container-fluid vs .container

its because ".container" class adds margin on both sides. instead use ".container-fluid" class on line 2 of your html

  <div class="container-fluid">

i think you are viewing it in a high resolution monitor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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