Home  >  Article  >  Web Front-end  >  How to define text right alignment in css

How to define text right alignment in css

WBOY
WBOYOriginal
2021-12-06 18:13:578340browse

In CSS, you can use the "text element {text-align:right;}" style to define the right alignment of the text; the "text-align" attribute is used to specify the horizontal alignment of the text in the element. When the value of the attribute is "right", the text arrangement will be aligned to the right.

How to define text right alignment in css

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

How to define text right alignment in css

In the HTML page, you can use the text-align attribute to set the text right alignment. The following example explains how to achieve right alignment of text in css.

1. Create a new HTML file, named test.html, to explain how to right-align text in CSS. Use the p tag to create a text for testing. Add a class attribute to the p tag for style setting. Write the tag, and the CSS style of the page will be written in this tag.

How to define text right alignment in css

2. In the css tag, set the style of the p tag through class, define its width as 200px, and the background color as gray. At the same time, use the text-align attribute to Set it to right to right-align the text.

How to define text right alignment in css

Open the test.html file in the browser to check the effect.

How to define text right alignment in css

Summary:

1. Use the p tag to create a text and add a class attribute to the p tag.

2. In CSS, set the style of the p tag through class, and use the text-align attribute to set it to right to achieve right alignment of the text.

(Learning video sharing: css video tutorial)

The above is the detailed content of How to define text right alignment in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn