Every webpage needs a containing element, but the body can serve as the main container.
You have two options:
body {
height:100%;
display: table;
margin: 0px;
padding: 0px;
}
h3 {
display: table-cell;
vertical-align: middle;
}
OR...
body {
height:100%;
margin: 0px;
padding: 0px;
}
h3 {
position: relative;
top: 50%;
}
Note that width-specific styles are unnecessary for this solution. Thanks to suggestions from Jason about setting margin and padding to 0px to eliminate scrollbars. Although some users reported the need to change "body" to "html, body" in Chrome, I did not encounter this issue with Chrome version 35.0. Testing in Safari and Firefox also yielded positive results.
Further adjustments were made due to feedback from Jason regarding the use of html5 doctype, which requires incorporating the html element with the body style. This adjustment may cause the scrollbar to reappear when using the relative position method. For additional information, check out the links provided below.
How can I vertically center text in a dynamically height div?