【发布时间】:2021-08-08 04:53:59
【问题描述】:
我不确定我错过了什么,我之前已经做过几次了,但是今天是与这个特殊的 CSS 作斗争的一天。我希望图像放大,但保持在尺寸范围内,因此缩放效果与任何放大效果相比。我试图将溢出:隐藏到其他父母或孩子中,但它没有效果。我也玩过显示设置。
有什么建议吗?上面是 JSfiddle 链接,下面是代码。感谢您的观看!
#purple-square {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/purple_card.png");
border-radius: 10px;
}
#migraine-dentistry {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/migraine_dentistry_card.png");
border-radius: 10px;
}
/* need position: relative in shell otherwisee the elements disappear */
#shell {
margin: auto;
width: 355px;
height: 255px;
position: relative;
transform-origin: center;
transition: 0.3s ease-in-out;
}
#shell:hover {
transform: scale(1.2);
}
#container {
width: 100%;
overflow: hidden;
display: inline-block;
transition: 0.3s;
margin: 0 auto;
}
#container div {
position: absolute;
left: 0;
transition: 0.3s ease-in-out;
}
#container:hover {
transition: ease-in-out 0.3s;
}
#container div.bottom:hover {
opacity: 0;
}
这是 HTML 设置:
<body>
<div id="shell">
<div id="container">
<div id='purple-square' class="top"></div>
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
【问题讨论】:
-
这能回答你的问题吗? Zoom on image inside div without div moving
标签: html css animation frontend css-animations