Helium87
Helium87

Reputation: 1

Display: Table-cell doesn't center the div

I am trying to center an image within a div and I used the display:table & display: table-cell method. It is centered but it is off by a few pixels from the top. What can I do to correct this?

CSS

html, body { 
    width: 100%;
    height: 100%;
}

body,html {
  margin: 0;
  padding: 0;
  color:#ffffff;
  text-align: center;
}

#wrapper{
text-align: left;
width: 940px;
margin: 0 auto;
margin-top: 22px;
background-color: #ffffff;
overflow: hidden;
}

header {
width: 908px;
height: 76px;
display: table;
border-style:solid;
border-top-width: 16px;
border-bottom-width: 16px;
border-top-color: #ffffff;
background-color: #cccccc;
}

#headerdiv { display: table-cell; vertical-align: middle; margin: 0; height: 28px; }



HTML

<div id="wrapper">

<header>
<div id="headerdiv"><img src="logotest.gif" height="28" width="180" alt="test"></div>
</header>

</div>

Upvotes: 0

Views: 1145

Answers (1)

j08691
j08691

Reputation: 207923

Add

img {
    vertical-align:middle;
}

jsFiddle example

Upvotes: 1

Related Questions