Solved

How to get div tag to sit vertically center of page

Posted on 2014-03-21
1
531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

710 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