Search code examples
htmlcsstwitter-bootstrapdropdownmultiline

Bootstrap 3.3 navbar drop-down text overflowing container


I am trying to create a notification widget like that used in Facebook, or Stack Overflow using the drop-down element of bootstrap. The contents are now breaking and flowing out of the container.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
      <li><a href="#">Link</a></li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
        <ul class="dropdown-menu" style="width: 300px">
          <li><a href="#">Action</a></li>
          <li><a href="#">Another action</a></li>
          <li><a href="#">Something else here Something else here Something else here Something else here Something else here Something else here Something else here Something else here</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">One more separated link</a></li>
        </ul>
      </li>
    </ul>
  </div>
</nav>

My list item looks like this:

<li><a>
<div class="row">
  <div class="col-md-4">
    <img/>
  </div>
  <div class="col-md-8">
    <b>Title</b><br />
    <span>Description</span>
  </div>
</div>
</a>
</li>

I tried adding clearfix and assigning the width to the span, but nothing helps.


Solution

  • All you need to do is add this to your css, it will make the content of your a wrap nicely:

    .navbar .nav li .dropdown-menu li a {
      white-space: normal;
    }
    

    codepen