CSS 响应图像定位在图像上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16363029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:43:40  来源:igfitidea点击:

Responsive images positioned over image

cssresponsive-design

提问by dclawson

I have setup a jsfiddle of what i'm trying to do:

我已经设置了我正在尝试做的 jsfiddle:

http://jsfiddle.net/MgcDU/3936/

http://jsfiddle.net/MgcDU/3936/

#counter {
    position: relative;
}
#over {
    position:absolute;
    left:33%;
    top:43%;
}

The image of the cat is my background image which resizes as the browser resizes.

猫的图像是我的背景图像,它会随着浏览器的大小调整大小。

The ball image is absolutely positioned over the cat. How can I get the ball image to resize and stay in the same position as it is my default?

球图像绝对位于猫上方。如何让球图像调整大小并保持与默认位置相同的位置?

回答by Marcel Gwerder

Set your #counterdiv to display: inline;or add a wrapper with display: inline;and set the max-widthof #overto for example 10%(DEMO):

您设置#counter股利display: inline;或增加包装与display: inline;和设置max-width#over为例子10%DEMO):

#counter {
    position: relative;
    display: inline;
}
#over {
    position:absolute;
    left:33%;
    top:43%;
    max-width: 10%;
}