textAlign style property
Specifies or returns the horizontal alignment of the text within the element.
Aligns text only for block elements. It has the same functionality as the align property.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: text-align |
Possible values:
The type of this property is string.
One of the following values:
Text is centered. | |||||||
Text is aligned to the left. | |||||||
Text is aligned to the right. | |||||||
Language dependent align rules. | |||||||
Text is centered. | |||||||
Text is aligned to the left. | |||||||
Text is aligned to the right. | |||||||
The text content of the element is centered. | |||||||
Text is aligned to the end of the element's box. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
The text content of the element is justified. | |||||||
Aligns the text content of the element to the left. | |||||||
Aligns the text content of the element to the right. | |||||||
Text is aligned the start of the element's box. |
Default: left.
Example HTML code 1:
This example illustrates the use of the text-align property:
|
||||
<head> <style> .alignLeft { text-align: left; } .alignCenter { text-align: center; } .alignRight { text-align: right; } </style> </head> <body> <div class="alignLeft"> Align to left </div> <div class="alignCenter"> Align to center </div> <div class="alignRight"> Align to right </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the textAlign property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeTextAlign (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var alignValue = selectTag.options[whichSelected].text; var div = document.getElementById ("myDiv"); div.style.textAlign = alignValue; } </script> </head> <body> <div id="myDiv">Change textAlign!</div> Change textAlign value: <select onchange="ChangeTextAlign (this);" size="4"> <option />left <option />right <option selected="selected" />center <option />justify </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
color
font
fontFamily
fontSize
fontSizeAdjust
fontStyle
fontVariant
fontWeight
textAlignLast
textAutospace
textDecoration
textIndent
textJustify
textKashidaSpace
textOverflow
textShadow
textTransform
textUnderlinePosition
font
fontFamily
fontSize
fontSizeAdjust
fontStyle
fontVariant
fontWeight
textAlignLast
textAutospace
textDecoration
textIndent
textJustify
textKashidaSpace
textOverflow
textShadow
textTransform
textUnderlinePosition
External links:
text-align (MSDN)
text-align (Mozilla Developer Center)
text-align (Safari Reference Library)
text-align (W3C)
text-align (Mozilla Developer Center)
text-align (Safari Reference Library)
text-align (W3C)
User Contributed Comments