4 extra vertical pixels?


I've got a header element that's constructed as follows:

<div id="header">
  <div id="title">
    <img src="images/logo.png" alt="Element17 Photography">
  <div id="menu">
      <li class="togglelink grey2white button" data-block="albums" id="togglealbums">Albums</li>
      <li class="togglelink grey2white button" data-block="about" id="toggleabout">About Me</li>
      <li class="togglelink grey2white button" data-block="contact" id="togglecontact">Contact</li>

The CSS to go with is as follows:

#header {left:10px; top:10px; position:absolute; height:80px; display:table;}
#title {display:table-cell; height:80px; margin:0; padding:0 20px 0 0; border-right:1px solid rgba(255,255,255,0.75);}
#menu {display:table-cell; vertical-align:middle; margin:0; padding:0; height:80px;}
#menu ul {list-style-type:none; margin:0 0 0 20px; padding:0; font-size:0.75em;}

I've specified an 80px height on basically every element, and yet in Chrome it's rendering at 84px in height. You can see it live here: www.element17.com.

Why is this happening?

Problem courtesy of: NaOH


That's because the <img> is a replaced inline element which sits on its baseline by default.

The image itself has a height of 80px and the extra vertical gap belongs to the line height reserved characters (descenders like: g j p q y).

You could simply fix that by aligning the image by vertical-align property with a value other than baseline:

img {
    vertical-align: middle; /* top or bottom */

For further information you can refer to this answer.

Solution courtesy of: Hashem Qolami


instead of using


you can use


#title {
    display: block;
    height: 80px;
    margin: 0;
    padding: 0 20px 0 0;
    border-right: 1px solid rgba(255,255,255,0.75);

You can find Detailed answer here

you can also remove white space in the markup by font-size:0px;

    display: table-cell;
    height: 80px;
    margin: 0;
    padding: 0 20px 0 0;
    border-right: 1px solid rgba(255,255,255,0.75);
    font-size: 0px;
Discussion courtesy of: Mehmet Eren Yener

This recipe can be found in it's original form on Stack Over Flow.