foreword
The project ui requires the text effect on the picture to be remarked
If you want to achieve this effect, you can use position: absolute
the layout
, but position: absolute
text-align:center
the problem of using invalidation
is the dislocation effect
How to solve?
Solution
method 1
padding
The orientation can be adjusted to achieve the centering
effect. First, look at the direction in which the text of the rendering ui is biased.
If it is no problem if it is upward, left, or right,
then we height
can make it smaller. For example, the size given by the ui is 50px. We can write a height of 40px
and use it padding-top:10px
to realize the text The problem of centering,
on the contrary, there is a deviation between the left and the right,
so we width
use the adjusted sizepadding-left或者right来动态调整
Method 2
There is also a full screen centered
position:absolute;
top:50px;
left:50%;
transform:(-50%,-50%);
This effect is suitable for 全屏居中
example : prompt pictures of empty pages, network disconnection prompts, etc.