Forum Moderators: not2easy

Message Too Old, No Replies

css column alignment

Works in IE but not firefox

         

max4

9:02 pm on Jun 6, 2008 (gmt 0)

10+ Year Member



Hi,

I'm converting my documents from XHTML 1.0 transitional to 1.1, and there are two bits of code that are getting in my way. The first is the html align attribute. I was able to convert most of the alignment attributes to work instead with the css {margin:0 auto;}. This allowed me to center layout elements nicely. However, I ran into trouble when I attempted to alter the following code:

<td align="center" colspan="2">
<div><div style="width:550px; text-align:left;">
<fieldset><legend>Subcategory</legend>

The above code centers a legend box within a table. Changing align="center" to style="text-align:center;" worked for IE but not firefox (in firefox the legend box moved to the left). Changing align="center" to style="margin:0 auto;" did not work for either IE or firefox. The problem continues with similar code that uses align="left" or align="right". I just don't know how to convert this last bit into CSS.

The second problem with switching to 1.1 is the xmlns. 1.1 does not recognize the lang="" attribute, in <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">.

Can I simply delete lang="en" since we already have xml:lang="en"?

Much thanks in advance,
Max

lavazza

10:42 pm on Jun 6, 2008 (gmt 0)

10+ Year Member



As I see no evidence of any eXtensibility in your HTML, I wonder why/if you have not considered converting to HTML4?

webmasterworld Why most of us should NOT use XHTML [webmasterworld.com]

max4

10:55 pm on Jun 6, 2008 (gmt 0)

10+ Year Member



Thank you for your concern, and for the information. Nevertheless, regardless of what I decide, it wouldn't hurt to know how to convert those remaining tid bits into css. It has become a challenge for me and I must find the answer (though to some, this might just be an easy tweak).

Max

swa66

7:06 pm on Jun 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Centering in css needs a width. A block level element e.g. gets a width of the available space (even if there are just 3 letters in it), so even if it actually does center, it'll not be what you want. (due to the large width it'll not make happen what you want to happen, set a background, some border to see what goes on)

While I don't agree with the do not use xhtml mantra personally. I read it, understand the arguments, but do not agree with the conclusion as long as as we learn to validate pages. Moreover it ignores the benefit of the ability to parse our code as it's xml.
That said, I'm partial about going up to 1.1, that one might be too soon for the browsers.

max4

12:46 am on Jun 8, 2008 (gmt 0)

10+ Year Member



Thanks for the reply swa66, you took the same stance as I in the xhtml issue and I'm starting to agree that I should hold off on the switch to 1.1. As for centering in css; I was hoping for another way but if that's what I have to work with, then I might just keep it simple and continue to use the align attribute - recognized in 1.0 transitional.

Max

SuzyUK

4:30 am on Jun 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, it's yes to the second one..

the first I think you're misunderstanding what it is you're centering? margin: 0 auto works fine both IE and FF, but it shouldn't be a direct replacement for td align="center"

td align="center" centers the contents of a table cell yes, but text-align: center; only centers the TEXT nodes, it does what it says on the tin

what you actually want to do *I presume* is center the div inside the table cell, so it's div that needs the margin: 0 auto, it's the one with width.

It's not actually the legend you're centering, but I think that was just the way you phrased it? correct me if I've picked that up wrong..

here's some sample code with colored legend that should hopefully explain

<!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" xml:lang="en" >
<head>
<title> Page Title </title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<style type="text/css" media="screen">
table {width: 100%; border: 1px solid #f00; table-layout: fixed;}
td {border: 1px solid #000; text-align: center;}
td div {width: 550px; text-align: left; margin: 0 auto;}
legend {background: #fcf;}
</style>
</head>
<body>
<table summary="">
<tr>
<td colspan="2">
<div>
<fieldset><legend>Subcategory</legend>
<form action="#"><p>some form elelments</p></form>
</fieldset>
</div>
</td>
</tr>
<tr><td>text aligned center</td><td>Hi</td></tr>
</table>
</body>
</html>

hth

max4

7:03 pm on Jun 8, 2008 (gmt 0)

10+ Year Member



Hi Suzy,

Thanks for the reply. I fixed the issue using the padding-left attribute (since it was within a table, the width is fixed and I don't have to worry about it expanding with the browser window or increased resolutions).

I had another question though. I finally passed 1.0 strict validation today, but a problem arose with firefox. I have an image that should appear at the very top of a table element with vertical-align:bottom, the image should be 41px away from the top of it's element (I set hight:41px;). In IE the image loads fine, exactly 41px below the top border, but in firefox the image only drops 37 px, 4 px away from its intended position.

Here is what I'm looking at:

----------
Edit
----------

I fixed the problem. All I had to do was add style="vertical-align:bottom;" to the image tag.

Thanks,
Max