gpt4 book ai didi

html - 网格中的元素不会根据动画调整大小

转载 作者:行者123 更新时间:2023-12-05 05:36:47 26 4
gpt4 key购买 nike

我有一个由四个正方形组成的网格,我希望其他正方形在悬停时扩展时相应地缩小。他们确实做出了回应,但只有在扩展广场的过渡完成之后。为什么他们要等到动画完成后再调整大小?是否可以这样做,以便他们实时响应不断扩大的广场?

main {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
width: 200px;
height: 200px;
gap: 10px;
transition: all 1s linear;
}

.square {
background-color: rebeccapurple;
width: 100%;
height: 100%;
transition: all 1s linear;
}

.square:hover {
width: 150px;
height: 150px;
transition: all 1s linear;
}

body {
display: flex;
justify-content: center;
}
    <body>
<main>
<div class="square" id="one"></div>
<div class="square" id="two"></div>
<div class="square" id="three"></div>
<div class="square" id="four"></div>
</main>
</body>

最佳答案

我只是did something similar (有关详细信息的相关文章:https://css-tricks.com/zooming-images-in-a-grid-layout/)

.gallery {
--s: 150px; /* control the size */
--g: 10px; /* control the gap */
--f: 1; /* control the scale factor */

display: grid;
gap: var(--g);
width: calc(2*var(--s) + var(--g));
aspect-ratio: 1;
grid-template-columns: repeat(2,auto);
}

.gallery > img {
width: 0;
height: 0;
min-height: 100%;
min-width: 100%;
object-fit: cover;
cursor: pointer;
transition: .35s linear;
}

.gallery img:hover{
width: calc(var(--s)*var(--f));
height: calc(var(--s)*var(--f));
}


body {
margin: 0;
min-height: 100vh;
display: grid;
place-content: center;
background: #60c4ff;
}
<div class="gallery">
<img src="https://picsum.photos/id/1028/300/300" alt="a forest after an apocalypse">
<img src="https://picsum.photos/id/15/300/300" alt="a waterfall and many rocks">
<img src="https://picsum.photos/id/1040/300/300" alt="a house on a mountain">
<img src="https://picsum.photos/id/106/300/300" alt="sime pink flowers">
</div>

它也适用于 div:

.gallery {
--s: 150px; /* control the size */
--g: 10px; /* control the gap */
--f: 1; /* control the scale factor */

display: grid;
gap: var(--g);
width: calc(2*var(--s) + var(--g));
aspect-ratio: 1;
grid-template-columns: repeat(2,auto);
}

.gallery > div {
width: 0;
height: 0;
min-height: 100%;
min-width: 100%;
cursor: pointer;
background: purple;
transition: .35s linear;
}

.gallery div:hover{
width: calc(var(--s)*var(--f));
height: calc(var(--s)*var(--f));
}


body {
margin: 0;
min-height: 100vh;
display: grid;
place-content: center;
background: #60c4ff;
}
<div class="gallery">
<div></div>
<div></div>
<div></div>
<div></div>
</div>

关于html - 网格中的元素不会根据动画调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73254150/

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