text-align Attribute | textAlign Property
Sets or retrieves whether the text in the object is left-aligned, right-aligned, centered, or justified.
Syntax
HTML { text-align: sAlign } Scripting object.style.textAlign [ = sAlign ]
Possible Values
sAlign String that specifies one of the following values:
left Text is aligned to the left. right Text is aligned to the right. center Text is centered. justify Text is justified. The property is read/write with a default value of left; the cascading style sheets (CSS) attribute is inherited.
Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see dynamic properties.
Remarks
The justify possible value is available as of Internet Explorer 4.0.
Because this property is inherited, all block-level objects inside a DIV object having textAlign=center are centered.
Example
This examples uses the text-align attribute and the textAlign property to align text within the object.
This example uses P as a selector and two classes to call an embedded style sheet that aligns the text according to the respective rule.
Sample Code
<STYLE> P { text-align:center } .align1 { text-align:right } .align2 { text-align:justify } </STYLE> </HEAD> <BODY> <P onclick= "this.className='align1'" ondblclick="this.className='align2'"> . . . </P>This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.This example uses inline scripting to change the alignment of the text when an onmouseover event occurs.
<P STYLE="font-size:14" onmouseover="this.style.textAlign='center'"> . . . </P>
Applies To
[ Object Name ] Platform Version Win16: Win32: Mac: Unix: WinCE: Version data is listed when the mouse hovers over a link, or the link has focus. BLOCKQUOTE, BODY, CENTER, currentStyle, DD, DIR, DIV, DL, DT, FIELDSET, FORM, Hn, HR, INPUT type=password, INPUT type=text, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, runtimeStyle, style, TABLE, TD, TEXTAREA, TH, TR, UL, XMP
Did you find this topic useful? Suggestions for other topics? write us!
© 1999 microsoft corporation. all rights reserved. terms of use.