Html 为什么赢了';我的元素上的z索引是否有效?
我有我的代码设置,所以我有英雄形象在底部和覆盖在顶部的文字和按钮覆盖。我还有一个带有z索引的导航栏,但由于某种原因,我的简历在overlay中的按钮不起作用 HTMLHtml 为什么赢了';我的元素上的z索引是否有效?,html,css,z-index,Html,Css,Z Index,我有我的代码设置,所以我有英雄形象在底部和覆盖在顶部的文字和按钮覆盖。我还有一个带有z索引的导航栏,但由于某种原因,我的简历在overlay中的按钮不起作用 HTML 因为z-index仅适用于未设置为位置:静态的元素。请记住,每个元素都默认设置为位置:static 尝试设置为位置:绝对或相对您的元素 还有所有其他类型的定位,比如位置:固定的,位置:粘性的,,所以我看了一下你的代码,你的按钮不起作用的原因是,ID为#hero的div(包含按钮)位于身体下方,因为它的z指数是-1 将#hero的
因为
z-index
仅适用于未设置为位置:静态的元素。请记住,每个元素都默认设置为位置:static
尝试设置为位置:绝对代码>或相对
您的元素
还有所有其他类型的定位,比如位置:固定的
,位置:粘性的
,,所以我看了一下你的代码,你的按钮不起作用的原因是,ID为#hero的div(包含按钮)位于身体下方,因为它的z指数是-1
将#hero的z-index设置为0或更高,按钮将工作
#hero {
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: 0;
}
查看我为您创建的JS小提琴:
编辑:哦,我忘了提一下——既然你想让图像在下面,就把英雄的z-索引设为1,把英雄法师设为0,然后叠加设为2。这应该可以做到(如果我认为你想要的是正确的)。z-index只在元素position
设置为absolute
或relative
时起作用。在这个线程中,关于position的所有注释都是无关的,任何查看CSS的人都可以看到它已经设置在父元素上。或者位置:sticky
。我添加了一个相对于#nav的位置,但什么也没有发生。overlay中的resume(恢复)按钮已经有了一个相对位置,这是不起作用的。这确实是这个特定问题的唯一正确答案。@AmandaFarrington-记住接受正确答案,以帮助其他人更快、更有效地从这个问题中找到帮助。如果我可以,但我是一个新用户,还需要一个信誉点来投票。。
#header {
color: #D7DADB;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size : 15px;
text-align: left;
width: 100%;
padding-left: 3em;
position: relative;
height: 15%;
box-sizing: border-box;
padding-top: 1em;
}
#header img
{
float: left;
padding-left: 3em;
}
h1{
width: 9em;
float: left;
padding-left: 0.5em;
color: #45CCCC;
padding-bottom: 1px;
}
#nav {
width: 50%;
margin:0;
padding:0;
text-align: right;
color: red;
font-size:20px;
float: right;
padding-right: 2em;
z-index: 99;
}
#nav ul {
padding: 1px;
}
#nav li {
display: inline;
padding: 38px;
}
#nav li a {
color: #2C3E50;
text-decoration: none;
}
#nav li a:hover {
color: #45CCCC;
}
/*----------hero image styles-------------*/
#hero{
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: -1;
}
#heroImage
{
top: 9%;
width: 100%;
z-index: 1;
position: absolute;
}
#overlay{
width: 34em;
top: -15%;
margin-left: 30%;
z-index: 2;
position: relative;
clear: left;
}
h2{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 60px;
float: center;
color: white;
opacity: 1.0;
text-shadow: 2px 2px 3px #000000;
text-align: center;
}
h3{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 30px;
color: #e5e5e5;
opacity: 1.0;
text-shadow: 2px 3px 2px #000000;
text-align: center;
}
a.down{
z-index: 100;
font-family: 'Roboto', sans-serif;
font-weight: 400;
text-decoration: none;
color: #181b1e;
background: #45CCCC;
position: relative;
padding: 0.6em 0.2em;
font-size: 1.2em;
-webkit-border-radius: 6px;
width: 30%;
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
}
a.down:hover{
text-decoration: underline;
color: white;
}
#hero {
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: 0;
}