Referring in this instance

指在这个实例中

I can not get the div with id="covered" on top of the div with id="cover" simply by using the z-index.

仅通过使用z索引,我无法在id="cover"的div上获得id="cover"的div。

Is there any other solution?

还有别的解决办法吗?

Code from http://codepen.io/anon/pen/jhgtf :

代码从http://codepen。io /不久/钢笔/ jhgtf:

HTML:

HTML:

<div id="cover"></div>
<div id="covered"></div>

CSS:

CSS:

#cover{
  position:fixed;
  width:800px;
  background:black;
  height:350px;
  z-index:10;
}
#covered{
  width:80px;
  background:yellow;
  height:50px;
  z-index:11;
}

3 个解决方案

#1


8

You need to specify a position on #covered:

你需要在上面指定一个位置:

#cover{
  position:fixed;
  width:800px;
  background:black;
  height:350px;
  z-index:10;
}
#covered{
  position: fixed;
  width:80px;
  background:yellow;
  height:50px;
  z-index:11;
}

CodePen example

CodePen例子

Elements with static (default) positioning are not affected by z-index - only positioned elements with fixed, relative, or absolute positioning are. Which of those you should use is dependent on context.

具有静态(默认)定位的元素不受z索引的影响——只受具有固定、相对或绝对定位的元素的影响。你应该使用哪一个取决于上下文。

Official z-index specification

官方的z - index规范

更多相关文章

  1. Jquery在两个元素之间更改文本
  2. 通过PHP隐藏SQL中的索引值
  3. HTML哪些是块级元素,哪些是行内元素、
  4. 如何使用CSS消除元素的偏移?
  5. KeyPress或KeyDown事件没有得到html元素的buind
  6. 行内元素与块级元素
  7. 固定定位,父元素具有转换
  8. 在c#中获取html元素的实际边距
  9. 两个堆叠的元素与他们旁边的元素成比例增长

随机推荐

  1. Python 虚拟环境 windows平台 virtualenv
  2. 轮询Web服务的最佳方式(例如,对于Twitter应
  3. 生成使用AES包装的RSA私钥
  4. 整理python dict list set 增删改查
  5. Tensorflow入门程序MNIST学习
  6. numpy无法将值分配给列的一部分
  7. python及其模块下载集合
  8. 在python中出现搜索项的打印行
  9. python基础编程_12_日期格式的使用和转换
  10. 从零开始部署Django生产环境(适用:《跟老齐