?
Solved

How do I center div tags?

Posted on 2011-05-04
2
Medium Priority
?
307 Views
Last Modified: 2012-05-11
I am trying to center the layer on the screen and it isn't working. Any ideas? I also need it to extend fluidly to the content.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #FFFFFF;
}
body {
	background-color: #ccecf3;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	margin:0px;
	padding:0px;
	text-align:center;
}
* {
	margin:0;
	padding:0;
}
a {
	font-size: 12px;
	color: #009fc2;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #009fc2;
}
a:hover {
	text-decoration: none;
	color: #009fc2;
}
a:active {
	text-decoration: none;
	color: #009fc2;
}
#container {
	position:relative;
	left:0px;
	top:0px;
	width:960px;
	height:750px;
	margin-right: auto;
	margin-left: auto;
	text-align:center;
}
.bl {
	position:absolute; 
	background: url(images/bl.gif) 0 100% no-repeat #ffffff;
	width: 75%;
}
.br {background: url(images/br.gif) 100% 100% no-repeat}
.tl {background: url(images/tl.gif) 0 0 no-repeat}
.tr {background: url(images/tr.gif) 100% 0 no-repeat; padding:10px}
.clear {font-size: 1px; height: 1px}
-->
</style>
</head>

<body>
<div class="container">
  <div class="bl"><div class="br"><div class="tl">
      <div class="tr">
        <p>BODY CONTENT HERE</p>
        <p>&nbsp;</p>
      </div>
    </div></div></div>
    </div>
</body>
</html>

Open in new window

0
Comment
Question by:kallestie
2 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 total points
ID: 35691703
To center it, change the CSS like so:

.bl {
      background: url(images/bl.gif) 0 100% no-repeat #ffffff;
      width: 75%;
        margin: auto;
}

Any div with a width and margin: auto will center.
0
 
LVL 2

Author Closing Comment

by:kallestie
ID: 35691881
Thanks! That worked! :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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 …
Suggested Courses

840 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