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

藏色散人
Release: 2020-11-17 11:18:05
Original
4791 people have browsed it

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;
}
Copy after login

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>
Copy after login

to set the following style for the i tag

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

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%;
}
Copy after login

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!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template