Solved

How to get div tag to sit vertically center of page

Posted on 2014-03-21
1
521 Views
Last Modified: 2014-04-07
How do I get the content div to sit vertically center?

<!DOCTYPE html>
<html charset="UTF-8">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Test</title>
	<link rel="stylesheet" type="text/css" href="styles/styles.css" />	
	<link href='http://fonts.googleapis.com/css?family=Italianno' rel='stylesheet' type='text/css'>

	<!--[if lt IE 7]>
		<style type="text/css">
			#wrapper { height:100%; }
		</style>
	<![endif]-->
	
</head>

<body>

	<div id="wrapper">
		
		<div id="header">
		</div><!-- #header -->
		
		<div id="head-banner">
			<p>
			<img src="imgs/kevinbarlow.png" />
			Building Contractor
			<span>Key West, Florida</span></p>
		</div>
		
		<div id="content">
		</div><!-- #content -->
		
		<div id="footer">
		</div><!-- #footer -->
		
	</div><!-- #wrapper -->
	
</body>

</html>

Open in new window



html,
body {
	margin:0;
	padding:0;
	height:100%;
}
html{
	background: url(S12_Blueprints.gif) no-repeat center center fixed;
	-webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
#wrapper {
	min-height:100%;
	width: 100%;
	position:relative;
}
#header {
	background:#000000;
	height: 20px;
	padding:0;
	border-bottom: 2px solid red;
}
#head-banner{
	height: 75px;
	max-width: inherit;
	margin-top: 0;
	margin-bottom: 0;
	background-color: #ffffff;
	-webkit-box-shadow: 0 8px 6px -6px black;
	-moz-box-shadow: 0 8px 6px -6px black;
	box-shadow: 0 12px 12px -3px black;
}
#head-banner p{
	/*display: inline-block;*/
	vertical-align: middle;
	margin-top: 0;
	color: gray;
	font-weight: bold;
}
#head-banner span{
	font-family: 'Italianno', cursive;
	font-size: x-large;
	padding-left: 20px;
}
#head-banner img{
	vertical-align: middle;
	padding-right: 30px;
	padding-left: 20px;
}
#content {
	min-width: 100%;
	height: 300px;
	vertical-align: middle;
	border: 1px solid black;
}

#footer {
	background:#ffab62;
	width:100%;
	height:100px;
	position:absolute;
	bottom:0;
	left:0;
	border: 1px solid black;
	-webkit-box-shadow: 0 -12px 10px -3px black;
	-moz-box-shadow: 0 -12px 10px -3px black;
	box-shadow: 0 -12px 10px -3px black;
}

Open in new window

0
Comment
Question by:centem
1 Comment
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 39945542
vertical align does not apply to div.  Change  content style to set the display property to a table cell:

#content {
	min-width: 100%;
	height: 300px;
	vertical-align: middle;
	border: 1px solid black;
        display:table-cell;
}

Open in new window

 That will vertically center the text to the middle of the div.

More examples of divs displayed as table cells can be found on my site.

Lternatives are to use the CSS calc() function with vh as the unit of measure; but that only works on the latest browsers and has some issues in Chrome; or you can use scripting to position during the load, but that has all kinds of cross browser issues if you are supporting.

Or you can just set margins or padding to simulate vertical centering.
Cd&

Cd&
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now