<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>层叠</title>
<style>
.c1{
width: 200px;
height: 200px;
background-color: #800080;
position: relative;
z-index: 2;
/*
* 如果元素的层级一样 下面的元素会盖住上面的元素
*
* z-index的值越大 层级越高
*/
opacity: 0.5;
/*opacity设置透明度 0不透明 1透明 0.5半透明*/
}
.c2{
width: 200px;
height: 200px;
background-color: #FF0000;
/*
* 开启绝对定位
*/
position: absolute;
/*设置偏移量*/
top: 100px;
left: 100px;
z-index: 1;
}
.c3{
width: 200px;
height: 200px;
background-color: #880000;
position: absolute;
left: 200px;
top: 200px;
}
</style>
</head>
<body>
<div class="c1"></div>
<div class="c2"></div>
<div class="c3"></div>
</body>
</html>
网页基础(二十五)z-index
猜你喜欢
转载自blog.csdn.net/qq_41440413/article/details/104670372
今日推荐
周排行