skip to Main Content

The following code produces “pills” of unequal width when displayed on small or extra small screens (as defined by twitter bootstrap by default).

<header>
    <div id="brand" class="container">
        <div class="row">
            <div class="col-sm-12">
                <h1>Website</h1>
                <h2>header</h2>
            </div>
        </div>
    </div>

    <div id="navbar" class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navs">
          <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 id="navs" class="collapse navbar-collapse">
            <ul class="nav nav-pills nav-justified">
                <li class="active">
          <a href="/home">Home</a>
                </li>
                <li>
                    <a href="/about">About</a>
                </li>
                <li>
                    <a href="/portfolio">Portfolio</a>
                </li>
                <li>
                    <a href="/blog">Blog</a>
                </li>
                <li>
                    <a href="/contact">Contact</a>
                </li>
            </ul>
        </div>
    </div>
</header>

The first pill seems to be exactly 2 pixels wider than the rest. I would prefer that the pills fill the entire width of the display.

Is this a bug in Bootstrap, or something I can remedy via some simple CSS?

JSFiddle: https://jsfiddle.net/elikmiller/z2og3vq7/

2

Answers


  1. You should use another class in your html called nav-stacked. I updated your Fiddle you can see here the full example and can see here the relevant HTML part.

      <ul class="nav nav-pills nav-stacked nav-justified">
        <li class="active">
          <a href="/home">This one is 2px wider</a>
        </li>
        <li>
          <a href="/about">About</a>
        </li>
        <li>
          <a href="/portfolio">Portfolio</a>
        </li>
        <li>
          <a href="/blog">Blog</a>
        </li>
        <li>
          <a href="/contact">Contact</a>
        </li>
      </ul>
    
    Login or Signup to reply.
  2. why don’t you override bootstrap css with your custom css just add your custom class for example nav-custom and put this css into your custom css file

    .nav-custom>li>a {
          padding: 10px 10px;
    }
    

    fiddle

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search