1

Since it is recommended not to use table elements for layout purposes (non-tabular data), because the special formatting applied to those elements may change in the future, is it also not recommended to use CSS properties such as text-align, which was designed to be used on text, for img elements for the same semantic reason?

I have been looking through the w3c specifications and for instance, line-height seems to be designed for text purposes and has plenty of references in the documentation to font size, so would it be appropriate or abusive to use this property on img elements, simply because they are displayed as inline?

I can understand how the W3C idea of a Semantic Web would use CSS to remove styling information from a page, leaving data exclusively in the HTML for content accessibility. But where is the original rationale documentation for CSS, and why wouldn't they use extremely abstract properties like horizontal-align from the get go, instead of unique alignments for each display type (e.g. text-align: center can be used on all display: inline elements such as img elements) ?

Community
  • 1
  • 1
Alex W
  • 37,233
  • 13
  • 109
  • 109
  • 1
    From what I've seen, CSS defines much formatting (accounting for many, *many* edge cases) and little semantic, if any. – BoltClock Aug 01 '12 at 16:22
  • 1
    @BoltClock So basically CSS isn't concerned with semantic usage in the same way that HTML and its elements such as `b` vs `strong` are? – Alex W Aug 01 '12 at 16:33
  • @AlexW: The big idea is to separate content from presentation. CSS is meant to describe the presentation, not the semantic content. – Mechanical snail Aug 01 '12 at 16:46
  • @Mechanicalsnail So if that was the original rationale behind CSS, why would CSS not be extremely simple and abstract starting at CSS1? – Alex W Aug 01 '12 at 16:51

2 Answers2

3

No. CSS is purely presentational. Some of the properties are just poorly named (text-align being a prime example, it is designed to align all inline children).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    It seems that this is the case, but when I thought about it it seems that CSS could be *greatly* simplified to just `vertical-align` and `horizontal-align` for all elements and become very abstract, right? – Alex W Aug 01 '12 at 16:37
  • I looked for documentation that contained the w3c rationale behind CSS, but didn't come up with anything concerning this. – Alex W Aug 01 '12 at 16:37
  • @Alex W: Sure it could, but it'd break old browsers horribly. – BoltClock Aug 01 '12 at 16:38
  • 1
    The strange this is that both 'text-align' and 'vertical-align' have been in the spec since CSS1. – Allan Kimmer Jensen Aug 01 '12 at 16:40
0

It is perfectly fine, to use text-align in table cells, that just styling the table as you should be doing. If you want to. Just do it in CSS. Do not use align="right".

https://developer.mozilla.org/en/CSS/text-align Says it applies to: block level elements, table cells and inline-blocks. So it is a use that is documented and intended. If you have inline content use this property to style its alignment.

http://www.w3.org/TR/CSS21/text.html#propdef-text-align Also states

This property describes how inline-level content of a block container is aligned.

So it is not just text, but all inline content.

Allan Kimmer Jensen
  • 4,333
  • 2
  • 31
  • 53