Solved

How to get div tag to sit vertically center of page

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

776 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