简体   繁体   English

在网格中放大的 div 的左侧和右侧垂直居中 div

[英]Vertically center divs to the left and right of an enlarged div in a grid

I have a ul of div s in a grid that are all the same size and distance from each other.我在网格中有一个uldiv ,它们的大小和距离都相同。 When the user selects one of the divs, it enlarges.当用户选择其中一个 div 时,它会放大。 This makes the divs to the left and right of this div look bad.这使得这个 div 左侧和右侧的 div 看起来很糟糕。 I'd like them to be vertically centered so it doesn't look as off.我希望它们垂直居中,这样看起来就不会那么糟糕了。 Here's a picture of what I have:这是我所拥有的图片:

我拥有的

Here's what I want:这是我想要的:

我想要的是

My current CSS (I'm using SASS) is:我当前的 CSS(我使用的是 SASS)是:

#grid {
    margin: 0 auto;
    padding: 0;
    text-align: center;
    list-style-type: none;

    li {
        display: inline-block;
        overflow-y: auto;
        text-align: right;
        vertical-align: top;
        width: 140px;
        height: 140px;
        background: #000;
        padding: 10px;
        margin: 5px;
        cursor: pointer;
    }

    .selected {
        width: 250px;
        height: 250px;
    }
}

When the user selects one of the divs, I give it the class .selected , so it becomes larger than the others.当用户选择其中一个 div 时,我给它类.selected ,所以它变得比其他的大。

Also, how do I animate the centering/enlarging?另外,如何为居中/放大设置动画?

you can use vertical-align: middle to make the vertical alignment centered.您可以使用vertical-align: middle使垂直对齐居中。 To animate you can add a transition on all or just on width and height , something like this:要制作动画,您可以在all或仅在widthheight上添加过渡,如下所示:

.box {
  width: 100px;
  height: 100px;
  background: teal;
  display: inline-block;
  vertical-align: middle;
  margin: 5px;
  transition: all 0.2s;
  or transition: width 0.2s, height 0.2s;
}

.selected {
  width: 250px;
  height: 250px;
  transition: all 0.2s;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM