html - 样式化 div 悬停 Action 不移动其他元素

标签 html css angular sass

我在屏幕上有一个包含 100 个元素的列表,有些描述比 div 的宽度长,所以我将它的剩余部分剪掉以保持它们的大小相同。在悬停时,我想显示所有数据。我设法做到了,但现在当我将鼠标悬停在一个元素上时,下面的所有元素都在向下移动。我想将悬停的 div 向前移动并将所有其他图 block 保持在同一位置。

Demo here

<div class="album-item">
  <div class="album-img"><img src="https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/1a/69/cf/1a69cf82-2cfe-a7e1-a79c-cb9d7d67b710/886447513651.jpg/170x170bb-85.png"></div>
  <div class="album-card">
    <div class="name">Rent (Original Soundtrack of the Fox Live Television Event)</div>
    <div class="artist">Original Television Cast of Rent Live</div>
    <div class="date">February 1, 2019</div>
  </div>
</div>

<div class="album-item">
  <div class="album-img"><img src="https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/1a/69/cf/1a69cf82-2cfe-a7e1-a79c-cb9d7d67b710/886447513651.jpg/170x170bb-85.png"></div>
  <div class="album-card">
    <div class="name">Rent (Original Soundtrack of the Fox Live Television Event)</div>
    <div class="artist">Original Television Cast of Rent Live</div>
    <div class="date">February 1, 2019</div>
  </div>
</div>
.album-item {
  background-color: gray;
  width: 170px;
  margin: 25px;
}

img {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  border-radius: 5px;
  -webkit-transition: all 0.6s cubic-bezier(0.15, 0.8, 0.4, 1);
  transition: all 0.6s cubic-bezier(0.15, 0.8, 0.4, 1);
  opacity: 0.8;
  border: 1px solid transparent;

  &:hover {
    -webkit-transform: scale(1.1, 1.1);
    transform: scale(1.1, 1.1);
    opacity: 1;
    border-color: yellow;
    cursor: pointer;
  }
}

.album-card {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  &:hover {
    color: yellow;
    white-space: normal;
    height: 100%;
  }

  .name {
    font-size: 110%;
    font-weight: 550;
  }

  .artist {
    font-weight: 300;
  }

  .date {
    font-weight: 100;
    font-style: italic;
    font-size: 80%;
  }
}

我希望图像描述显示在下面图像的顶部,这样它就不会移动整个列表。

最佳答案

不复制内容:https://codepen.io/dmegatool/pen/jdmOgq

这就是您想要的效果吗?

新的CSS:

.album-item {
  width: 170px;
  margin: 25px;
  margin-bottom:75px;
}

img {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  border-radius: 5px;
  -webkit-transition: all 0.6s cubic-bezier(0.15, 0.8, 0.4, 1);
  transition: all 0.6s cubic-bezier(0.15, 0.8, 0.4, 1);
  opacity: 0.8;
  border: 1px solid transparent;


  &:hover {
    -webkit-transform: scale(1.1, 1.1);
    transform: scale(1.1, 1.1);
    opacity: 1;
    border-color: yellow;
    cursor: pointer;
  }
}

.album-card {
  display:block;
  position:absolute;
  width:170px;
  background-color: gray;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;


  &:hover {
    color: yellow;
    white-space: normal;
    height: auto;
    z-index:10;
  }

  .name {
    font-size: 110%;
    font-weight: 550;
  }

  .artist {
    font-weight: 300;
  }

  .date {
    font-weight: 100;
    font-style: italic;
    font-size: 80%;
  }
}

未修改的 HTML:

<div class="album-item">
  <div class="album-img"><img src="https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/1a/69/cf/1a69cf82-2cfe-a7e1-a79c-cb9d7d67b710/886447513651.jpg/170x170bb-85.png"></div>
  <div class="album-card">
    <div class="name">Rent (Original Soundtrack of the Fox Live Television Event)</div>
    <div class="artist">Original Television Cast of Rent Live</div>
    <div class="date">February 1, 2019</div>
  </div>
</div>

<div class="album-item">
  <div class="album-img"><img src="https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/1a/69/cf/1a69cf82-2cfe-a7e1-a79c-cb9d7d67b710/886447513651.jpg/170x170bb-85.png"></div>
  <div class="album-card">
    <div class="name">Rent (Original Soundtrack of the Fox Live Television Event)</div>
    <div class="artist">Original Television Cast of Rent Live</div>
    <div class="date">February 1, 2019</div>
  </div>
</div>

关于html - 样式化 div 悬停 Action 不移动其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54485064/

相关文章:

Angular 2 单元测试 http.get 未定义

html - Angular 4 使用箭头键从文本字段滚动到 <li>

php - 在文本区域中将新行更改为 <br>

html - HTML中不关闭标签和属性的实际问题是什么

javascript - 在 processing.js 中检测鼠标接近度

css - slider 中的文字在 ie 中变粗变粗

css - 隐藏密码显示在 IE 中不起作用

html - Facebook 喜欢 div 下面的按钮偏移,即使没有边距或填充

javascript - 触发多层元素的悬停行为

angular - 取消 ngrx 效果中的计时器