Log in

View Full Version : How to center the legend element in a fieldset



Moshambi
05-20-2009, 06:35 AM
Is it possible to get the legend text in a <fieldset> to be in the center rather than on the left? Thanks

Snookerman
05-20-2009, 08:17 AM
Unfortunately the <legend> tag can be quite difficult to control. This might be because <fieldset> and <legend> are non-presentational tags (although they might appear presentational).

After a lot of firebugging, the only solution I could find is not only deprecated, but also invalid (yaiks)! What I would recommend is to leave it the way it is, but I'll show you my highly unsemantic solution anyways:

<legend align="center">Tables for layout, yaay!</legend>
I'm sure that wouldn't even validate in the 90's but it's the only one that does the job. The choice is yours.

Good luck!

Medyman
05-20-2009, 01:48 PM
I'm sure that wouldn't even validate in the 90's but it's the only one that does the job. The choice is yours.

Who cares? It does the job so he should use it. Validation isn't everything. It's one thing if using align="center" on the <legend> tag would break something. But it won't. Validation shouldn't be the ultimate goal - usability and accessibility should. If centering the legend makes the page more user-friendly, then go for it.

In fact, if you're using the legend tag for it's original intent, it's the more semantic approach. I think you're confusing semantics and validation in your statement above.

Snookerman
05-20-2009, 02:09 PM
Who cares? It does the job so he should use it. Validation isn't everything. It's one thing if using align="center" on the <legend> tag would break something. But it won't. Validation shouldn't be the ultimate goal - usability and accessibility should. If centering the legend makes the page more user-friendly, then go for it.
I agree, but try telling that to some of my clients..


In fact, if you're using the legend tag for it's original intent, it's the more semantic approach. I think you're confusing semantics and validation in your statement above.
I didn't say it's unsemantic because it doesn't validate, I was just thinking there might be problems with screen readers (which I don't know anything about). Then again, I do tend to refer to semantics when I talk about the overall professionalism of a site so you're right.