CSS怎么让子元素叠在父元素的上面
1个回答
展开全部
父级position:relative; z-index:0;子级position: absolute; z-index:-1;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style type="text/css">
ul {
float: left;
}
ul li {
list-style: none;
margin: 7px 20px 6px 0;
float: left;
position: relative;
cursor: pointer;
background: $fff;
z-index: 999;
}
ul li span{
height: 20px;
padding: 0 5px;
line-height: 20px;
display:inline-block;
background:#fff;
border: #555 1px solid;
}
ul li:hover .sub-ul {
display: block;
}
ul li .sub-ul {
position: absolute;
width: 180px;
left: 0px;
border: red 1px solid;
background: #fff;
display: none;
z-index: -1;
top:10px;
}
ul li .sub-ul li {
border: none;
height: 23px;
margin: 0px;
line-height: 23px;
float: left;
}
</style>
<body>
<ul>
<li><span>手机</span>
<ul class="sub-ul cl">
<li>智能机</li>
<li>功能机</li>
<li>对讲机</li>
</ul>
</li>
</ul>
</body>
</html>
这样不就在父元素下面了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style type="text/css">
ul {
float: left;
}
ul li {
list-style: none;
margin: 7px 20px 6px 0;
float: left;
position: relative;
cursor: pointer;
background: $fff;
z-index: 999;
}
ul li span{
height: 20px;
padding: 0 5px;
line-height: 20px;
display:inline-block;
background:#fff;
border: #555 1px solid;
}
ul li:hover .sub-ul {
display: block;
}
ul li .sub-ul {
position: absolute;
width: 180px;
left: 0px;
border: red 1px solid;
background: #fff;
display: none;
z-index: -1;
top:10px;
}
ul li .sub-ul li {
border: none;
height: 23px;
margin: 0px;
line-height: 23px;
float: left;
}
</style>
<body>
<ul>
<li><span>手机</span>
<ul class="sub-ul cl">
<li>智能机</li>
<li>功能机</li>
<li>对讲机</li>
</ul>
</li>
</ul>
</body>
</html>
这样不就在父元素下面了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询