0

For my nav bar, I want to have my p tag line up with my a tags

CSS is here

#welcome {
    vertical-align: center;
    /* align: middle; */
    color: white;
}

HTML is here

<div id="navbar" class="navbar-collapse collapse">
  <ul class="nav navbar-nav navbar-right">
    <li id="welcome">
      <p>Welcome</p>
    </li>
    <li><a id="home" href="/index.html">Home</a></li>
    <li><a id="logout" href="/logout.html">Log out</a></li>
  </ul>
</div>

But this is what it looks like:

enter image description here

So how do I accomplish this?

OneMoreQuestion
  • 1,693
  • 3
  • 25
  • 51

3 Answers3

0

the easiest way would be to give the p tag the same line-height as the height of the navbar and remove its margins:

.navbar p {
    line-height:40px;
    margin:0;
}

the vertical-align property does no align elements vertically despite what it looks like. It only works in table cells and on inline-block elements. Also there is no vertical-align: center; its vertical-align: middle;

Dimitri L.
  • 4,499
  • 1
  • 15
  • 19
0

You can also do this :

<div id="navbar" class="navbar-collapse collapse">
  <ul class="nav navbar-nav navbar-right">
  <li><a id="welcome">Welcome</a></li>
    <li><a id="home" href="/index.html">Home</a></li>
    <li><a id="logout" href="/logout.html">Log out</a></li>
  </ul>
</div>

DEMO

bhansa
  • 7,282
  • 3
  • 30
  • 55
0

The vertical-align property tells an inline-block element how to align to its inline-block siblings.

Therefore your problem can be solved with the following code:

.nav li { 
    display: inline-block; 
    vertical-align: middle;
}