简体   繁体   English

Z索引堆叠顺序

[英]Z-index stacking order

Consider the following jsfiddle: http://jsfiddle.net/dHaM8 考虑以下jsfiddle: http : //jsfiddle.net/dHaM8

HTML: HTML:

<div class="first"><img src="http://placekitten.com/g/200/300"/></div>
<div class="second"></div>
<div class="third"><p class="test"> test test test </p></div>

CSS: CSS:

.first img {position:fixed; top: 10; left: 10; z-index: 1}
.test {position:fixed; top: 10; left: 10; z-index: 10}
.first {
    background-color: #a6a6a6;
    height: 600px;
    background-attachment: fixed;
    background-image: url("http://placehold.it/1000x500");
}

.second {
    background-color: #fff;
    min-height: 500px;
    z-index:2;
    position:relative;
}

 .third {
    background-color: #ff0000;
    min-height: 500px;
    background-attachment: fixed;
    position:relative;
    z-index:3;
 }

What i am trying to do is: 我想做的是:

The kitten should stay fixed within the div "first" which is already achieved if you look at the CSS. 小猫应该保持在div“ first”内,如果您查看CSS,这已经实现了。

However, the text in the third div is not displaying! 但是,第三个div中的文本未显示!

If i set the div higher to that of the kitten, the text will be displayed in the first div which i don't want to happen. 如果我将div设置为高于小猫的div,则文本将显示在我不想发生的第一个div中。 I only want it to be displayed in the third div. 我只希望它显示在第三个div中。

Help please. 请帮助。

Give position: relative to the <p> tag. 给出位置:相对于<p>标记。 See fiddle 小提琴

.test {position:relative; top: 10px; left: 10px; z-index: 10}

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

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