【发布时间】:2021-11-30 20:38:24
【问题描述】:
尝试使用悬停状态创建“流动网格”交互。
目标:将鼠标悬停在网格内的卡片上时,卡片的大小会增加,并“推动”其他列和行中的其他卡片,使其更小。
问题:我认为对网格父级使用“自动”大小会起作用,但事实并非如此。代码如下
.shape-card-container {
width: 100vw;
height: 100vh;
display: grid;
grid-template-columns: repeat(2, auto);
grid-template-rows: repeat(2, auto);
grid-column-gap: 4px;
grid-row-gap: 4px;
}
.shape-card {
width: 100%;
height: 100%;
background: blue;
border-radius: 64px;
cursor: pointer;
overflow: hidden;
transition: background 300ms cubic-bezier(0.66, 0.11, 0.03, 0.96);
}
.shape-card:hover {
width: 105%;
height: 105%;
}
<div class="shape-card-container">
<div class="shape-card">
</div>
<div class="shape-card">
</div>
<div class="shape-card">
</div>
<div class="shape-card">
</div>
</div>
【问题讨论】:
-
这能回答你的问题吗? CSS-only masonry layout
-
您要查找的内容称为砌体布局。然而,到目前为止,只有 Firefox 处于“beta”模式支持它。
-
OP 请求的行为似乎与砌体布局没有任何关系,这是一种在不同高度(有时是宽度)。