PDA

View Full Version : Centering a Div


shwaza
12-12-2004, 08:36 PM
Hi Guys, i am messing around with divs right now, and i have one in a table cell, i am wondering how i can get it to be centered within the cell. Any suggestions? i will put the html i have so far down there:


<html>

<head>

<title>Test Page</title>

</head>

<body>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="543" height="501" id="AutoNumber1">
<tr>
<td width="543" height="102" colspan="2"></td>
</tr>
<tr>
<td width="125" height="395"></td>
<td width="326" height="352" background="newtestsite.gif">


<div align="left" position="width: 25; height: 25;" style="width: 350; height: 350; overflow: auto;" >
<p align="center"><font size="6">Blah</font></p>
<p>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </div>

</td>
</tr>
</table>
</div>

</body>

</html>

Note: i used so many blahs just to make sure the scroll bar worked :P

mahangee
12-12-2004, 08:49 PM
Not quite sure what you mean, but couldnt you just use align="center" in the table cell, the div's in?

shwaza
12-12-2004, 09:19 PM
well, i tried that, and it didnt work :angry: and i dont really know anything about css so i figured i must be missing something

688206002
12-12-2004, 09:44 PM
It's pretty tricky to get divs to work properly inside table cells; the best solution is to take out tables altogether and just use divs.

shwaza
12-12-2004, 10:55 PM
darn, didnt really wanna do that :P i geuss i might have to then

bigface0
12-13-2004, 05:03 PM
Well you could go really old school and surround your div with <center></center> tags. That should work. But if you go with css surround everything in a <div id="outer"></div> and then the css would look like this.

div#outer{
position: relative;
width: 900px; /* change this dimension to whatever you want */
margin-left: auto;
margin-right: auto;
padding: 0px;
}

then any thing you want to position you do like this:
div#whatever{ /* change whatever to your div name */
position: absolute;
left: yoursizepx; /* change yoursize to a number */
top: yoursizepx; /* change yoursize to a number */
padding: 0px;
margin: 0px;
}
And the div is called <div id="whatever"></div>

shwaza
12-13-2004, 07:29 PM
well, i'd kinda rather stay away from css because im not too good with it, ill figure something out thow, i got another questions about divs, is it possible to add rows and coloms such as in tables?

reid315
12-14-2004, 02:00 AM
how about this:

fixed-width


body {
text-align: center;
}

#yourdiv {
width: whateveryoursize;
margin: auto; //margin: 10px auto; is valid as well
text-align: left;
}


fluid


#yourdiv {
width: 90%; //or whatever percentage you want.
margin: auto;
}


Edit: code