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
Solved

How to get div tag to sit vertically center of page

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

856 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