You mean your image is exactly the size of the screen?
Unless the aspect ratio of your image is the same as the screen ratio, the image will be deformed, either squashed or thinned, otherwise it will be what you said
The cover is full and the image may exceed it. Contain means that the image is completely inserted, and there may be some white space. I have also encountered this adaptation requirement. The current idea is to img width height100% low-level simulation background. If you don’t have time to try it yet, you can try it first.
Both cover and contain are scaled proportionally. Otherwise, use img 100% or background-size percentage. To make the background full-screen ratio, the ratio must be correct
The first method: Center the background image through positioning, and then adjust the background size to cover, so that the image will not be deformed and covered;
p {
background-size: cover;
background-position: center center;
}
The second method: achieve the full effect by forcing the width and height of the background image to 100%, but the image is easily deformed (not recommended).
You mean your image is exactly the size of the screen?
Unless the aspect ratio of your image is the same as the screen ratio, the image will be deformed, either squashed or thinned, otherwise it will be what you said
The cover is full and the image may exceed it. Contain means that the image is completely inserted, and there may be some white space.
I have also encountered this adaptation requirement. The current idea is to img width height100% low-level simulation background. If you don’t have time to try it yet, you can try it first.
Both cover and contain are scaled proportionally. Otherwise, use img 100% or background-size percentage. To make the background full-screen ratio, the ratio must be correct
The right or bottom part is incomplete, guessing that
background-position
does not havecenter
;cover
is filled with elements (with cropping),contain
is the largest background (leaving black borders), both of which maintain the aspect ratio;If you don’t want the aspect ratio, you can try
100% 100%
, which is deformed but can fill the elements without cropping;You can adjust the element size if necessary, just use js to do it dynamically.
The first method: Center the background image through positioning, and then adjust the background size to cover, so that the image will not be deformed and covered;
The second method: achieve the full effect by forcing the width and height of the background image to 100%, but the image is easily deformed (not recommended).