text-align

CSS text-align Property

The text-align property is used for aligning the inner content of a block element.

You can use the margin property to center the element.

Alignment specified with text-align is not with respect to the containing block or viewport.

类目类目
Initial Valueleft if direction is “ltr”, right if direction is “rtl”
Applies toBlock containers.
InheritedYes
AnimatableNo.
VersionCSS1
DOM Syntaxobject.style.textAlign = “right”;

Syntax

Syntax

text-align: left | right | center | justify | initial | inherit;

Example of the text-align property with the “right” and “center” values:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div {
        text-align: right;
      }
      p {
        text-align: center;
      }
    </style>
  </head>
  <body>
    <h2>Text-align property example</h2>
    <div>Example for the text-align property.</div>
    <p>Some paragraph for example.</p>
  </body>
</html>

Result

Example of the text-align property with the “center”, “left” and “justify” values:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      h2 {
        text-align: center;
      }
      p.date {
        text-align: left;
      }
      p.example {
        text-align: justify;
      }
    </style>
  </head>
  <body>
    <h2>Text-align property example</h2>
    <p class="date">March, 2019</p>
    <p class="example">
      Lorem Ipsum is dummy text of the printing and typesetting industry. Lorem Ipsum h as been the industry's standard dummy text ever since the 1500s when an unknown pri nter took a galley of type and scrambled it to make a type specimen book. It has surviv ed not only five centuries, but also the leap into electronic typesetting, remaining essent ially unchanged. It was popularised in the 1960s with the release of Letraset sheets conta ining Lorem Ipsum passages, and more recently with desktop publishing software like Ald us PageMaker including versions of Lorem Ipsum.
    </p>
  </body>
</html>

Values

Values

ValueDescriptionsPlay it
leftAligns the text to the left. This is the default value of this property.Play it »
rightAligns the text to the right.Play it »
centerAligns the text to the center.Play it »
justifyExtends the lines so that each line has equal width.Play it »
initialIt makes the property use its default value.Play it »
inheritIt inherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部