Home >Web Front-end >CSS Tutorial >How to align three words with two words in css

How to align three words with two words in css

藏色散人
藏色散人Original
2020-11-17 11:18:054793browse

How to achieve the alignment of three words and two words in css: first create an HTML sample file; then add "text-align: justify" and other styles to the specified div to achieve three words and two words Alignment.

How to align three words with two words in css

Recommended: "css video tutorial"

The requirements are as follows. The text in the red box must have four characters. , three-character, two-character, if you don’t align both ends, you can choose center alignment or right alignment. But what if you want to align both ends like below?

How to align three words with two words in css

I believe many people have done this before: use two characters to separate them to a width of four characters. Three characters are also acceptable, but, like the above In the picture, "122 account number" and "122 password" are difficult to calculate how many spaces should be used.

Suppose we have the following HTML:

There are only dreams and good girls in this world that cannot be let down!

Add some style to it

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

The initial effect is like this

How to align three words with two words in css

##text-align: justifyWhat is this thing? Text-align in CSS2 has an attribute value of justify, which means alignment. The effect achieved is that a line of text can be displayed aligned at both ends (the text content must exceed one line).

But just using it is still useless...

To align the text at both ends, we have to use an inline empty tag to help, such as , tag

<div>这世间唯有梦想和好姑娘不可辜负!<i></i></div>

to set the following style for the i tag

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

padding-left: 100% and width:100% can achieve the effect, Just choose one of them. The effect is as follows

How to align three words with two words in css

#But adding HTML elements violates the principle of separation of structure and presentation. We can use after and before pseudo-elements instead:

div:after {
    content: " ";
    display: inline-block;
    width: 100%;
}

The above is the detailed content of How to align three words with two words 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