re:从0开始的CSS之旅 18. z-index

1. z-index

z-index 属性用于设置元素的叠放层次,属性值可以为一个整数,整数值越大越优先显示

注意:z-index只对开启了定位的元素有效

示例如下:

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>

	div {
		width: 200px;
		height: 200px;
	}
	
	.box1 {
		background-color: #c7edcc;
	
		position: relative;
		left: 50px;
		top: 100px;
	
		z-index: -2;
	}
	
	.box2 {
		background-color: #fde6e0;
	
		position: absolute;
		left: 150px;
		top: 150px;
	
		z-index: -1;
	}
	
	.box3 {
		background-color: #dce2f1;
	
		float: left;
	}
	
	.box4 {
		background-color: red;
		position: fixed;
		left: 125px;
		top: 225px;
	}
</head>

<body>
	<div class="box1">相对定位</div>
	<div class="box2">绝对定位</div>
	<div class="box3">浮动</div>
	<div class="box4">固定定位</div>
</body>

</html>

相关推荐

  1. re:0开始CSS 18. z-index

    2024-02-17 06:30:01       24 阅读
  2. re:0开始CSS 17. 定位

    2024-02-17 06:30:01       28 阅读
  3. re:0开始CSS 19. 背景

    2024-02-17 06:30:01       28 阅读
  4. re:0开始CSS 15. 浮动

    2024-02-17 06:30:01       29 阅读
  5. re:0开始CSS 14. 显示模式切换

    2024-02-17 06:30:01       29 阅读
  6. re:0开始CSS 12. 轮廓、阴影、圆角

    2024-02-17 06:30:01       28 阅读
  7. re:0开始CSS 13. 文档流

    2024-02-17 06:30:01       26 阅读
  8. re:0开始CSS 16. 高度塌陷问题

    2024-02-17 06:30:01       27 阅读
  9. re:0开始CSS 20. 渐变(暂完结撒花)

    2024-02-17 06:30:01       26 阅读
  10. re:0开始CSS学习10. 盒子模型溢出

    2024-02-17 06:30:01       23 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-17 06:30:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-17 06:30:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-17 06:30:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-17 06:30:01       18 阅读

热门阅读

  1. Jenkins打包springboot项目到k8s

    2024-02-17 06:30:01       38 阅读
  2. leetcode77组合 剪枝条件详细解释

    2024-02-17 06:30:01       37 阅读
  3. 【无人机】PIXHAWK、PX4、APM区别

    2024-02-17 06:30:01       38 阅读
  4. 键盘快捷切换K线周期的设计与实现

    2024-02-17 06:30:01       37 阅读
  5. 设计模式之:状态模式(State Pattern)

    2024-02-17 06:30:01       32 阅读
  6. 设备驱动开发_2

    2024-02-17 06:30:01       23 阅读
  7. SpringBoot后端Long数据传到前端js精度损失问题

    2024-02-17 06:30:01       34 阅读