The effect and code are here
http://u6.gg/RJD
The final effect I want is as follows:
It is to put the user's avatar into the background frame. But when the window is reduced, the avatar moves out of position.
What are the methods? ? I saw that others could achieve it, but now I can’t find it.
There is a problem with the cutting of your picture. How can a large background be cut into one picture? The correct way is to cut the frame into one picture. When the background of p is, img is its child element, and the width is 100%. , this way there will be no problem no matter how you change it
I also think there is something wrong with your cutout. I can barely achieve your request, but it is not a long-term solution.
HTML
CSS
Jsfiddle view
Pay attention to what the arrow in the picture points to:
In your style settings:
backgorund-size:contain
,然后我试着放大缩小了,结果,图片本身并没有发生多大的变化,就是不能同步缩放。我也不懂contain
这个属性是啥意思...,自己百度吧。。。把这个设置成background-size:auto
That’s it.Another thing is that the position of your background image is set to the
center center
,即水平,垂直居中。所以你的图片也要设置成水平,垂直居中。关于如何水平垂直居中的,这个你只能百度,google。。了,我这边提供的是css3
centered method.means to set the picture to be horizontally and vertically centered.
The result of my test here is ok, you can try it...
Set the image as the background image of the frame. Delete the img tag. Set background-size:cover