textAlign property

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

 

Syntax

Integer value = object.put_textAlign( v);Integer value = object.get_textAlign(* sAlign);

Property values

Type: BSTR

one of the values listed in Possible Values.

left (left)

Default. Text is aligned to the left.

right (right)

Text is aligned to the right.

center (center)

Text is centered.

justify (justify)

Text is justified.

String format

left | right | center | justify

CSS information

Applies To All elements
Media visual
Inherited 1
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 IHTMLStyle::textAlign attribute and the IHTMLStyle::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.

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

<!DOCTYPE html>
<html>

<head>
  <title>text-align</title>
  <style>
    p {
      text-align: center;
    }

    .align1 {
      text-align: right;
    }

    .align2 {
      text-align: left;
    }
  </style>
</head>

<body>
  <p onclick="this.className='align1'" ondblclick="this.className='align2'">
    The text is aligned to the center using <strong>p</strong> as<br>
    the HTML selector in the stylesheet.<br>
    Click the text to align right.<br>
    Double-click to align left.
  </p>
</body>

</html>

This example uses inline scripting to change the alignment of the text when an HTMLFrameSiteEvents::onmouseover event occurs.

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

<!DOCTYPE html>
<html>

<head>
  <title>textAlign</title>
</head>

<body>
  <p style="font-size: 14pt" onmouseover="this.style.textAlign='center'" 
       onclick="this.style.textAlign='right'" 
       ondblclick="this.style.textAlign='left'">
    Run your mouse over me to<br>
    center the text.<br>
    Click to make me align to the right.<br>
    Double-click to align left.
  </p>
</body>

</html>

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Mshtml.h

IDL

Mshtml.idl

DLL

Mshtml.dll