tags:

views:

290

answers:

6

I think I'm pretty good at using semantic markup on my pages but I still have a handful of classes like this:

/**** Aligns ****/
.right_align  { text-align: right; }
.left_align   { text-align: left; }
.center_align { text-align: center; }

Which, technically, is a no-no. But when you just want to position some text in a table, how crazy am I supposed to get with the semantic markup?

+1  A: 

Semantic markup is an admirable goal, but in the real world, you sometimes have to make compromises. In some cases, the only sensible way to do something is to break semantics and just throw in a right_align.

Edit: People seem to be misunderstanding my point in this. You should use semantic markup where possible. However, there are cases where it really is just a stylistic choice and there is nothing inherent to the data that you can use to describe or classify it. This is most typically true with large sections of tabular data, especially if it is dynamically generated.

I've had cases where clients want to be able to dynamically control what columns appear in data grid. There's no way to know ahead of time what type of data they're going to choose to show. If they want a way to center or right align a dynamically generated column, it's better to have center and right align classes available for them to use than to have them sticking style attributes everywhere.

Jeromy Irvine
Like Jeremy Keith, I would also describe myself as "borderline semantically psychotic". But I voted this answer up because I agree that people are probably misunderstanding the point.
Andy Ford
Thank you, Andy, I appreciate it. I tend to be pretty hard nosed when it comes to semantic markup, too, but I've been bitten by the client bug too many times to toe the line too fervently anymore. :)
Jeromy Irvine
+10  A: 

Why do you want to align the text?

The answer to the question is the name of the id or class you need to have for your selector. Do you want to align it right because it's a price?

table .price {
  text-align: right
}

Just ask yourself why do you want to apply a particular style, and all will become clear.

I probably overdid it, but my last work project was pretty close 100% semantic- anything I needed which was not semantic (say, a filler div which I could not do without for a layout requirement), I added dynamically using jQuery.

alex
If you add it dynamically, doesn't that mean that your site won't display properly without Javascript, making it less accessible, against the spirit of why we're using semantic markup?
Jeremy Banks
Good point. I didn't do as much testing as I should, but I'm pretty sure the site was quite accessible without JS. And on a no-CSS, no-JS situation, it was pretty much 100% usable.
alex
Your answer is very good, but I think that is always very easy to contradict someone that says "my last web project is 100% semantic". Or pretty close. Can we see the code of one of your 100% semantic page? Could born a very interesting discussion about semantic.
alexmeia
Better: open a new question in wich you post a 100% semnatic page and ask: can you find something of non semantic here? We well see that the concep of semantic is not a digital one.
alexmeia
What's the difference between "100% semantic" and "semantic"? I know, this is just semantics...
Rimian
OK, guys, I mean it was as semantic as reasonably possible :-pI've abandonded using Javascript for the uses I mentioned in my post since then :-p
alex
+2  A: 

If you want tight coupling between the table cells and the alignment, you could just assign the attribute style="text-align:right" directly on the tag. There is no reason to go the extra level of indirection through a class if you dont use it for a level of abstraction anyway.

JacquesB
A: 

100% semantic markup is a silly goal. Your graphic designer will say, "Let's right align this", and the reason will be "because it looks good that way". What are you supposed to do, add a class of "looksgoodthatway" to the div? Just right align it and get on with your life! :)

Ned Batchelder
Later the designer decides that it would look good if the aligned thingy also had a background image. Do you change the name of the class then?
JacquesB
+2  A: 

I try to consider why I want a column right aligned in a table. For example, if the column contains currency amounts then I would use a style named currency instead of right_align.

g .
A: 
Kent Fredric
Both very good points but not really what the poster was asking about.
Ola Tuvesson