April 30th, 2003, 11:42 PM
a few questions about CSS
1. what's the equavelent of align="center" in CSS? The only thing I have noticed is text-align, but that doesn't help when I want to center a table. P.S. I must say no to deprecated tags like <center>
2. I want to include 2 classes in an element, such as td class="td" class="td1", but of course only one can be included normally. Is there a way to use both?
text-align does work:
<table style='width:90%; background-color:yellow;'>
should hopefully prove that.
Not sure if you're going for some sort of standards compliance, but I don't think putting a <table> inside a <p> will validate as XHTML. Don't know if it matters, but if it does, I'll offer another solution.
As for two classes on one element, no can do. But you can use an ID and a class in combination with each other, and if you look over where you have the two classes, you'll probably find that makes more sense logically.
thank you all.
for the first problem, I've settled with <div class="center">, which seems to work, and special thanks to adios for the link.
Okay, it turned out things were not so simple. Apparently, the <div class="center"> works fine with IE, but Netscape will not do. On the other hand, the solution jharnois presented will ONLY work with Netscape, not with IE. Ahh, the frustration of customized browsers support.
I think for what I suggested you have to have the container's style have text-align:center. So if you're centering a table inside the body, apply text-align:center to the body. If it's a nested table inside a div, apply it to the div. All of that in addition to what I already posted.
Notice that the property is text-align? Yes. Text. Inline elements. Not block-level elements.
The correct way of centering blocks is:
Or if you know you won't have any top/bottom margins, you can just say:
margin: 0 auto;
The fact that IE aligns blocks with text-align is a known bug - please don't perpetuate it's usage.
Yes, while using text-align to align a block-level element is technically incorrect, there are serveral known bugs that require the use of some kind of workaround, and that is the workaround for the problem stated.