Solved

How to get div tag to sit vertically center of page

Posted on 2014-03-21
1
524 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

912 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

20 Experts available now in Live!

Get 1:1 Help Now