[] Tips] CSS text is aligned at both ends, and css text is aligned at both ends

Source: Internet
Author: User

[] Tips] CSS text is aligned at both ends, and css text is aligned at both ends

The requirements are as follows. The text in the red box contains four words, three words, and two words. If the two sides are not aligned, you can select center or right. But what if the two ends are aligned like below?

I believe many people have done this before: two words can be separated to reach the width of four words, and three words can also be separated. However, for example, in the "122 account" and "122 password" section, it is difficult to calculate how many spaces should be used.

Suppose we have the following HTML:

<Div> In this world, only a dream and a girl can live up to it! </Div>

Add a style to it

div{  width:500px;  border:1px solid red;  text-align: justify;}

The initial effect is as follows:

text-align: justifyWhat is this? CSS2text-alignThere is a property valuejustify, Indicates alignment. The result is that the two sides of a line of text can be displayed in alignment (more than one line of text content ).

But it is still useless .....

To align the two ends of the text, we have to use an empty label in the row to help, such<span>,<i>Wait. I used it here.<i>Tag

<Div> In this world, only a dream and a girl can live up to it! <I> </div>

Give thisiLabel settings:

div i{  display:inline-block;  /*padding-left: 100%;*/  width:100%;}

padding-left: 100%Andwidth:100%Can achieve the effect, choose one. The effect is as follows:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.