text-align property (Internet Explorer)

Switch View :
ScriptFree
text-align property

[This documentation is preliminary and is subject to change.]

Sets or retrieves whether the text in the object is left-aligned, right-aligned, centered, or justified.

CSS 2.1, Section 5.4.6

Syntax

text-align: left | right | center | justify

Property values

A variable of type String that specifies or receives one of the following values:

left

Default. Text is aligned to the left.

right

Text is aligned to the right.

center

Text is centered.

justify

Text is justified.

CSS information

Applies ToAll elements
Mediavisual
Inherited1
Initial Value

Standards information

Remarks

The property applies to block elements. The property is inherited by all block-level objects inside a div object. This parameter receives null if the attribute is not set.

The justify possible value is available as of Microsoft Internet Explorer 4.0.

Examples

The following examples use the text-align attribute and the text-align 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.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/text-align.htm


<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 example uses inline scripting to change the alignment of the text when an onmouseover event occurs.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/textAlign.htm


<P STYLE="font-size:14" 
    onmouseover="this.style.textAlign='center'">
. . . </P>

 

 

Build date: 3/14/2012

Community Content

yecril
INPUT type=text
An input field is not a block-level element; the behaviour of Internet Explorer is nonstandard.

yecril
Odd behaviour under Transitional DTD

As of IE7, text-align is not inherited by tables if the document type is transitional.