使用z-index用图像重叠div [英] Overlapping a div with an image using z-index

查看:183
本文介绍了使用z-index用图像重叠div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS动画在图像后面不断播放。当图像未加载时,它将显示,但加载时,图像将与动画重叠。我使用z-index来实现这一点,但它不工作。

A CSS animation is continuously playing behind an image. When the image is not loaded it will display, but when loaded the image will overlap the animation. I'm using z-index to achieve this, but it's not working.

图片应该使用z-index属性隐藏加载动画。

The image should hide loading animation with the z-index property.

strong>我无法使用任何JavaScript解决方案隐藏加载动画并在加载图片后显示。

Note: I can't use any javascript solution to hide the loading animation and show it after image load.

CSS / HTML /演示

CSS / HTML / Demo

.leftprev {
    overflow:auto;
    position:absolute;
    height:99%;
    width:85%;
}
.loadingslide {
    z-index: 50; /* Loading div's z-index */    
}
.spinner.big {
    display: block;
    height: 40px;
}
.spinner {
    bottom: 0;
    display: none;
    font-size: 10px;
    height: 30px;
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    text-align: center;
    top: 0;
    width: 60px;
}
.spinner.big > div {
    width: 6px;
}
.spinner > div {
    animation: 1.2s ease-in-out 0s normal none infinite stretchdelay;
    background-color: #333;
    display: inline-block;
    height: 100%;
    width: 6px;
}
a {
    color: #470a09;
    text-decoration: none;
}
.slideshow .slidebro .leftprev #slideshowpic {
    display: block;
    margin: 0 auto;
    width: auto;
    z-index: 100; /* image's z-index */    
}

<div class="leftprev">
    <div class="loadingslide"> <!-- Loading Animation div (should be running in background of the image) -->
        <div id="tracking" class="spinner big">
            <div class="rect1"></div>
            <div class="rect2"></div>
            <div class="rect3"></div>
            <div class="rect4"></div>
            <div class="rect5"></div>
        </div>
    </div>
        <a id="targetslide" target="_blank" title="Click to view fit to screen" href="">
          <img src="http://www.placehold.it/500" alt="" id="slideshowpic" />  <!-- The image (should mask the loading animation div) -->
        </a>
</div>    

推荐答案

请将位置添加到要应用 z-index 的元素。

You have to add position to the element that you want to apply z-index.

p>

From CSS-tricks:


CSS中的z-index属性控制重叠的
元素的垂直堆叠顺序。在中,哪一个看起来像是物理上
更接近你。 z-index只影响位置为
值而非static(默认值)的元素。

The z-index property in CSS controls the vertical stacking order of elements that overlap. As in, which one appears as if it is physically closer to you. z-index only effects elements that have a position value other than static (the default).

http://css-tricks.com/almanac/properties/z/z-index/ < a>

http://css-tricks.com/almanac/properties/z/z-index/

这篇关于使用z-index用图像重叠div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆