定义和用法

z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面。

注释:元素可拥有负的 z-index 属性值。

注释:Z-index 仅能在定位元素上奏效(例如 position:absolute;)

说明

该属性设置一个定位元素沿 z 轴的位置,z 轴定义为垂直延伸到显示区的轴。如果为正数,则离用户更近,为负数则表示离用户更远。

优先关系

如果同时出现两个相同的z-index值,那么在后面的元素层级会高于前面的元素。例如:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>z-index</title>
</head>
<style type="text/css">
.first{width:200px; height: 500px; position: absolute; background:#00f; z-index: 100;}
.second{width:250px; height: 250px; position: absolute; background:#f33; z-index: 100;}
</style>
<body>
<div class="first">first</div>
<div class="second">second</div>
</body>
</html>

类名为second的div会在类名为first的div上面。

z-index属性是区分所有兄弟元素的高度,并不是所有页面元素的高度;例如:

<style type="text/css">
.first{width:200px; height: 500px; position: absolute; top: 0; background:#00f; z-index: 80;}
.second{width:250px; height: 250px; position: absolute; top: 50px; background:#f33; z-index: 100;}
.first-child{width:250px; height: 250px; position: absolute; top: 0; background:#333; z-index: 101;}
</style>
<body>
<div class="first">first
<div class="first-child">first-child
</div>
</div>
<div class="second">second</div>
</body>

类名为first-child的div元素的z-index大于类名为second的div元素的z-index;但页面显示效果first-child位于second下面

最新文章

  1. sprint3冲刺第一天
  2. c#面向对象基础 封装、继承
  3. DMSFrame 之SqlCacheDependency(一)
  4. android学习笔记24——事件处理
  5. Java开发的一个简单截屏工具
  6. WCF大数据量传输解决方案
  7. 【转】通用分页用户控件(DataGrid,DataList,Repeater都可以用它来分页)
  8. oracle 12c 学习系列(1)–12c初体验
  9. QML Flipable、Flickable和状态与动画 上篇
  10. 39. leetcode 326. Power of Three
  11. C-图文上边对齐
  12. Pythonh中的zip()与*zip()函数详解
  13. 设置eclipse全局编码格式
  14. JavaScript调试总结
  15. SpringCloud(一)Eureka注册中心
  16. board_led.h/board_led.c
  17. 从github checkout子文件夹
  18. Oracle使用par文件进行全库导入导出
  19. style标签下的CSS代码的显示与实时编辑
  20. php中array_map和array_walk的使用对比_php技巧

热门文章

  1. 转载:windows下安装mac虚拟机(Vmvare+mac)
  2. Java Review (一、Java开发环境)
  3. iOS-Code Data多线程的封装详解
  4. 头条面试居然跟我扯了半小时的Semaphore
  5. Koa源码解析,带你实现一个迷你版的Koa
  6. 关于vue不能像angular深度克隆数据解决办法
  7. Jquery封装:下拉框插件
  8. redis的5种数据结构和基本操作
  9. Java 多线程基础(五)线程同步
  10. 素数筛 : Eratosthenes 筛法, 线性筛法