gpt4 book ai didi

html - 图像设置为适合 'grandparent' 但隐藏在 'parent' 内

转载 作者:行者123 更新时间:2023-11-28 01:18:52 25 4
gpt4 key购买 nike

我有一个有点复杂的问题,

我想让IMAGE设置full size到DIV,但是要隐藏到另一个DIV里面..

我会尽力解释:

#grandParent {
width: 100%;
height: 500px;
border: 2px solid black;
position: relative;
}

#parent {
width: 50%;
height: 100%;
overflow: hidden;
border: 1px solid red;
}

#child {
width: 100%;
height: auto;
position: absolute;
}
<div id="grandParent">
<div id="parent">
<img id="child" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Liliumbulbiferumflowertop.jpg/220px-Liliumbulbiferumflowertop.jpg">
</div>
</div>

进行了修改^^

感谢广告:)

最佳答案

这样的事情可能会起作用:

.grandParent {
border: 1px solid;
width: 500px;
height: 500px;
display: flex;
justify-content: center;
align-items: center;
}
img {
width: 500px;
height: 500px;
}
.parent {
width: 250px;
height: 250px;
overflow: hidden;
}

编辑:也许我有更好的主意。

Code Pen

关于html - 图像设置为适合 'grandparent' 但隐藏在 'parent' 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51639261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com