[英]HTML - Z-index with transition
我的 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.