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>
<div id="menu">
<ul>
<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>
</ul>
</div>
</div>
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?
instead of using
display:table-cell
you can use
display:block
#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;
#title
{
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;
}
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: gjpqy).
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.