PDA

View Full Version : Div and Content Placement



JimmyS
01-02-2007, 07:17 PM
Before I begin let me just say that I have tried everything I could from google to do this and nothing worked for me.

I am trying to center my div on the screen, yet have the content in that div right justified.

I use,


#titles {
float: left;
text-align:right;
background-color: #dddddd;
margin-left: auto;
margin-right: auto;
}

for the division.

I added a container that uses the below and nothing still


#form {
float: left;
width: 100%;
text-align: center;
margin: 0 auto;
}


Any help would be appriciated.

Excavator
01-02-2007, 07:32 PM
Hello JimmyS,
The way you have it now, your not really giving your content anything to center on because you have either width: 100% or no width set at all.
Try it like this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body {
text-align: center;
background-color: #CCCCCC;
}
#form {
width: 600px;
text-align: center;
margin: 0 auto;
background-color: #FFFFCC;
}
#titles {
width: 300px;
float: left;
text-align:right;
background-color: #dddddd;
}
</style>
</head>
<body>
<div id="form">
<div id="titles">
<p>some text here</p>
</div>
</div>
</body>
</html>

JimmyS
01-02-2007, 07:43 PM
I just kinda assumed if you didn't set the width that the width was automaticlly determined. :)

Anyway, that worked, thanks for the help boss. :thumbsup:

Excavator
01-02-2007, 08:04 PM
I just kinda assumed if you didn't set the width that the width was automaticlly determined.

It is. It automatically takes up all the space available.