css - How to center single-line and multi-line text
过去多啦不再A梦2017-05-16 13:26:34
0
8
1747
as the picture shows,
When there is only one line in this line, the text is vertically centered. When there are two lines of text, the text is also vertically centered. How to do it?
Judging from your layout, it should look like this: the text on the left and the time on the right are both vertically centered. A simple method is: layout:<p><span>gfghghg</span><span>2017-12<s/pan></p> css: p{display: table ;} span{display: table-cell; vertical-align: middle;}
According to the picture you provided, each piece of content has a fixed height, so set the line-height of the outermost parent element equal to the p tag display in its own height: inline-block; vertical-align: middle; Code structure
You can take a look at these methods I summarized. Portal What the subject needs is a method to vertically center multi-line text. The article I summarized contains typical methods to achieve this. Examples are as follows. http://codepen.io/zengkan0703... I wonder if it was the questioner who disliked my answer? If so, I hope I can be answered why. If not, the above example should solve your needs.
Look at the renderings first
Then the code implementation
Judging from your layout, it should look like this: the text on the left and the time on the right are both vertically centered.
A simple method is:
layout:<p><span>gfghghg</span><span>2017-12<s/pan></p>
css:
p{display: table ;}
span{display: table-cell; vertical-align: middle;}
You can try it
Contains various solutions and portals
<p class="" style="display: table;height: 100px;">
According to the picture you provided, each piece of content has a fixed height, so set the line-height of the outermost parent element equal to the p tag display in its own height: inline-block; vertical-align: middle;
Code structure
You can take a look at these methods I summarized. Portal
What the subject needs is a method to vertically center multi-line text. The article I summarized contains typical methods to achieve this. Examples are as follows.
http://codepen.io/zengkan0703...
I wonder if it was the questioner who disliked my answer? If so, I hope I can be answered why. If not, the above example should solve your needs.