3

According to W3Schools the property is used to "align text within elements".

When using it in different ways however, like buttons, it also works perfectly. See this JsFiddle

Is it a good idea to use the align-text CSS property in situations like this or is something else a better solution like putting float: right on the button?

I was wondering if this attribute was intended only for text or if the name was just chosen poorly.

(as pointed out by Ray Toal, the answer is in the official W3C spec)

MarioDS
  • 12,895
  • 15
  • 65
  • 121
  • 1
    Oh noes! You linked to the W3 *Schools* description of the property, NOT the W3C's specification! They are not the same thing at all! The W3C spec is [here](http://www.w3.org/TR/2003/CR-css3-text-20030514/#alignment-prop). You can see it aligns inline elements within their block, just as the accepted answer states. [Beware of W3Schools](http://w3fools.com/)! – Ray Toal Oct 01 '12 at 00:26
  • @RayToal that was indeed a bad mistake to make. I didn't know W3Schools had nothing to do with W3C. Thanks for pointing out that I should avoid it. – MarioDS Oct 01 '12 at 00:35

2 Answers2

3

To be more accurate, it is used to align text and inline elements within their parents.

So spans, buttons, elements with display:inline-block and so on will be aligned according to text-align, whereas block-level elements are unaffected (but may inherit the container's text-align and apply it to further descendants).

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Okay, so it's for text and anything that is also inline. Thanks. I wonder why they didn't call it "horizontal-align" or simply "align" then, like the attribute name that can be used in html elements (I know that is really bad though) – MarioDS Oct 01 '12 at 00:19
1

Your use of text-align is perfectly fine here. Using floats would then need to clear following elements from their effects, etc

Perfectly fine: I wouldn't say that of the HTML code of your example (table, no label, no for/id association)

FelipeAls
  • 21,711
  • 8
  • 54
  • 74
  • Haha, I just whipped up some random HTML quickly to have some sort of context for my question. Don't worry, I'm not **that** bad when I use html in production environment :) – MarioDS Oct 01 '12 at 00:13