Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display text only on the collapsed navbar in Bootstrap?

I'd like to display a telephone number that appears on the navbar next to the navbar toggle button. The toggle button only appears once the navbar is in the collapsed state. I'd like the text to appear next to it.

Here's what I have now:

collapsed navbar

And here's what I am trying to achieve:

collapsed navbar with text

HTML from the relevant divs:

<div class="header-centered"><img src="http://placehold.it/350x150"></div>
<div class="navbar">
  <div class="navbar-inner">
    <div class="container">
      <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
      <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>

      <!-- Everything you want hidden at 940px or less, place within here -->
      <div class="nav-collapse collapse">
        <ul class="nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">Link1</a></li>
          <li><a href="#">Link2</a></li>
          <li><a href="#">Link3</a></li>
          <li><a href="#">Link4</a></li>
          <li><a href="#">Link5</a></li>
        </ul>
      </div>
    </div>
  </div>
</div>

I don't want the text to appear unless the navbar is collapsed. How can this be achieved?

like image 371
Tom Brossman Avatar asked Jan 14 '23 03:01

Tom Brossman


1 Answers

You can control the visibility of your text by CSS, something like this:

.abcde .text {
  display: none;
}
.abcde.collapse .text {
  display: inline-block;
}
like image 196
Jefferson Henrique C. Soares Avatar answered Jan 21 '23 17:01

Jefferson Henrique C. Soares