4 replies [Last post]
libman
Offline
newbie
Last seen: 16 years 24 weeks ago
Joined: 2004-04-22
Posts: 6
Points: 0

Hi Folks,

Newbie here. My question:

Why doesn't the following in tablelayout center my table?
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;

Thanks so much for your time and patience. I was following a tutorial at Lynda.com and I thought I did everything correctly.

Greg at

Hre's my html:
***************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

<LINK REL=StyleSheet HREF= "new.css" TYPE="text/css">
</head>

<body>
<table id="tablelayout">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>
**************************

Here's my css sheet:
**************************
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: .8em;
line-height: 1.5ex;
color: #000000;
padding: 0px;
margin-top: 46px;
margin-right: 0px;
margin-bottom: 10px;
margin-left: 0px;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #FFFFFF;
text-decoration: none;
}
a:active {
color: #FFFFFF;
}
table, td {
padding: 0px;
border-collapse: collapse;
}
tablelayout {
color: #660000;
background-color: #0099FF;
width: 750px;
border-top: 1px solid #660000;
border-right: 1px solid #660000;
border-bottom: 1px solid #660000;
border-left: 1px solid #660000;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
*********************************

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 4 years 30 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

Why Doesn't this table css work- doesn't center table

Hi

There are 3 browser methods for centering page content, and I have described them in this thread:

http://www.csscreator.com/css-node/1308

This shows how to satisfy all three browser types in one go.

As to your design. You have made only one mistake.

In the style sheet, you need a # in front of the tablelayout style name:

#tablelayout {

To tell the browser to apply it to an element by the name/id of tablelayout.

Trevor

libman
Offline
newbie
Last seen: 16 years 24 weeks ago
Joined: 2004-04-22
Posts: 6
Points: 0

thanks; but now I'm confused even though it works

Hi Trevor,

Well I placed text-align:center in the body tag in my css file and all worked. Jeeze, now I'm really confused! How in the world did anyone figure this fix out? Gads!

Can you tell me what problems this may cause?

Well, I guess I should email lynda.com and tel them about this problem. No doubt they have had a number of emials in regards to this.

Thanks again Trevor.

Peace Out,
Greg

libman
Offline
newbie
Last seen: 16 years 24 weeks ago
Joined: 2004-04-22
Posts: 6
Points: 0

on centering td elements in the table body

If you have the time, what is the procedure for vertical and horizontal center, middle aligning all table eleemnts, text and images.

Thanks,
greg

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 4 years 30 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

Why Doesn't this table css work- doesn't center table

Hi

I'm not really into table etc, so you would have to experiment with valign and align in the td elements, or the img's.

Centering vertically in css is fraught with problems.

Not enough time to explain it here.

Trevor