绝对图像位置(不允许图像进入div)

时间:2022-02-06 20:31:53

I have tried to search everywhere, but cant find out how to prevent image to stay in its parent div when image have absolute positioning (when zooming image its go outside of the div). hidden overflow not helping at this point. Thanks for advices.

我试图在任何地方搜索,但是当图像具有绝对定位时(当将图像缩放到div之外时),无法找到如何防止图像保留在其父div中。隐藏的溢出在这一点上没有帮助。谢谢你的建议。

3 个解决方案

#1


2  

When you absolutely-position an element, it will position itself inside the nearest positioned parent. So, add a position: relative to the CSS of your element's parent.

当你绝对定位一个元素时,它会将自己定位在最近的父元素内。因此,添加一个位置:相对于元素父级的CSS。

To make sure the parent contains the positioned element, you'll want to add overflow:auto to the parent's CSS as well.

为了确保父元素包含定位元素,您还需要将overflow:auto添加到父元素的CSS中。

#2


1  

add position: relative, to the parent div..

添加位置:亲,到父div ..

.parent_div {position: relative;}
.parent_div img {position: absolute; top: number; right: number;}

#3


0  

Add this style to the image:

将此样式添加到图像:

 style="width:inherit; height:inherit;"

#1


2  

When you absolutely-position an element, it will position itself inside the nearest positioned parent. So, add a position: relative to the CSS of your element's parent.

当你绝对定位一个元素时,它会将自己定位在最近的父元素内。因此,添加一个位置:相对于元素父级的CSS。

To make sure the parent contains the positioned element, you'll want to add overflow:auto to the parent's CSS as well.

为了确保父元素包含定位元素,您还需要将overflow:auto添加到父元素的CSS中。

#2


1  

add position: relative, to the parent div..

添加位置:亲,到父div ..

.parent_div {position: relative;}
.parent_div img {position: absolute; top: number; right: number;}

#3


0  

Add this style to the image:

将此样式添加到图像:

 style="width:inherit; height:inherit;"