HTML - 带过渡的 Z-index

标签 html css django figure

我的 html 元素有问题。当我对图像进行吸尘时,它会变大,但不会覆盖彼此相邻的图像。 (只剩一个)

https://i.imgur.com/oNP4gHA.png https://i.imgur.com/g2zIoSr.png

CSS:

.photo {

  margin: 10px 0;
  width: 120px;
  background: white;
  padding: 10px;
  opacity: 1;
  border-radius: 5px;
  border: 1px solid silver;
  box-sizing: border-box;
  justify-content: space-around;
  flex-wrap: wrap;
  transform: rotate(5deg);
  transition: 0.3s all ease-in-out;
  will-change: transform;
  align-items: flex-start;
  display: inline-flex;

}

.photo img {
  flex-basis: 100%;
  width: 100px;
}

.photo figcaption {
  margin-top: 10px;
}

.photo:nth-child(even) {
  transform: rotate(-5deg) scale(0.8);
}

.photo:hover {
  opacity: 1;
  transform: scale(2.0);
  z-index: 10;

}

HTML

{% for i in zdjecie %}

   <figure class="photo" >
    <img src="{{i.url}}"
         alt="Kotek Robert">
    <figcaption>
      {{i.title}}
    </figcaption>
  </figure>

{% endfor %}

最佳答案

z-index 不会在具有 static 定位的对象上按预期运行。

position: relative 添加到您的 .photo 元素以解决问题:

.photo {
  margin: 10px 0;
  width: 120px;
  background: white;
  padding: 10px;
  opacity: 1;
  border-radius: 5px;
  border: 1px solid silver;
  box-sizing: border-box;
  justify-content: space-around;
  flex-wrap: wrap;
  transform: rotate(5deg);
  transition: 0.3s all ease-in-out;
  will-change: transform;
  align-items: flex-start;
  display: inline-flex;
  
  position: relative; /* add this */
}

.photo img {
  flex-basis: 100%;
  width: 100px;
}

.photo figcaption {
  margin-top: 10px;
}

.photo:nth-child(even) {
  transform: rotate(-5deg) scale(0.8);
}

.photo:hover {
  opacity: 1;
  transform: scale(2.0);
  z-index: 10;
}
<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

<figure class="photo">
  <img src="{{i.url}}" alt="Kotek Robert">
  <figcaption>
    {{i.title}}
  </figcaption>
</figure>

关于HTML - 带过渡的 Z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46855540/

相关文章:

html - Bootstrap 3 : Tooltip image just after the input field?

jquery - 有没有一种方法可以使用适用于所有浏览器的 jQuery 设置不透明度?

javascript - 使用 Javascript 模拟进度条

Django memoize 每个请求

django - 使用Django的ImageField,如何将文件存储在STATIC_ROOT中?

javascript - 使用 Javascript 添加行,但它显示然后变得不可见

html - 仅使用没有 jquery 或 java 脚本的 Css 从页面顶部到中间设置动画 div

javascript - 根据元素高度和宽度的百分比变化来增加或减小字体大小

jquery - 如何使按钮位于所有设备的右下角?

python - 文件字段在 Django 中不起作用