Reputation: 55
I wanted to make my text that is inside my CSS box vertically aligned on the middle. I tried valign="middle" on the div but it didn't work.
CSS:
#leadboard
{
width: 1300px;
height: 100px;
background-color: #dedede;
}
HTML:
<div id="leadboard" align="center">
<h1>Text Here</h1>
</div>
Upvotes: 0
Views: 68
Reputation: 165
Like this :
#leadboard
{
width: 1300px;
height: 100px;
background-color: #dedede;
display: table;
}
#leadboard h1
{
display: table-cell;
vertical-align: middle;
}
or
#leadboard
{
width: 1300px;
height: 100px;
background-color: #dedede;
line-height: 100px;
}
Upvotes: 1
Reputation: 1630
If your text is one line -
#leadboard {
line-height: 100px; /* Equal to height */
}
If your text is several lines -
#leadboard {
display: table;
}
#leadboard h1 {
display: table-cell;
vertical-align: middle;
}
Upvotes: 1