html - CSS 中的子元素悬停/链接

标签 html css hover

我试图让一些元素在用户将鼠标悬停在它们上面时稍微移动(它们在导航栏上形成按钮)。但是,我的代码似乎不起作用。框中的文本也应该是可点击的,但这似乎也不起作用。这是代码:

#navbar {
position: relative;
width: max-width;
height: auto;
margin-left: 2%;
}

.nav_tab{
background-image: url('dark_exa.png');
border: 2px dashed grey;

/* rounded borders of 5px in firefox */
-moz-border-radius:10px;  

/* rounded borders of 5px in chrome and other browsers */
-webkit-border-radius:10px;  

/* rounded borders of 5px in browsers that support css3 */
border-radius:10px;

/* shadows for different browsers */
-moz-box-shadow: 0 0 0 3px black, 2px 1px 4px 4px rgba(10,10,0,.5);
-webkit-box-shadow: 0 0 0 3px black 2px 1px 4px 4px rgba(10,10,0,.5);
box-shadow: 0 0 0 3px black, 2px 1px 6px 4px rgba(10,10,0,.5);
position: relative;
height: auto;
width:20%;
z-index: -1;
margin-left: 2%;
margin-right: 2%;
top: -30px;
display: inline-block;
}

.nav_tab:hover{
position: relative;
top: +5px;
}

h1 {
font-size:40px;
text-align: center;
color: white;
font-family: "Gabriela";
margin: 20px;
margin-top: 130px;
}
h2 {
font-size:30px;
text-align: center;
color: white;
font-family: "Gabriela";
margin: 10px;
margin-top: 40px;
}

和 HTML:

<div id="navbar">
<div class="nav_tab"><h2><a href="http://www.stackoverflow.com">Zues</a></h2></div>
<div class="nav_tab"><h2>Jack</h2></div>
<div class="nav_tab"><h2>Denise</h2></div>
<div class="nav_tab"><h2>Joel</h2></div></div>

我不完全确定这里发生了什么,但我认为这是某种亲子问题。

谢谢。

最佳答案

链接不可点击,因为您给 .nav_tab 类一个负的 z-index 值,只需将其调整为值 => 0 即可。

关于html - CSS 中的子元素悬停/链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15311733/

相关文章:

html - 让 flex 盒子项环绕多行高的子项

html - 子菜单(下拉菜单)被截断并且不显示在移动设备上

java - 将鼠标悬停在文本上不改变颜色 - libgdx

javascript - 尝试调用位于另一个函数内部的函数

html - CSS/HTML float div 继承父级的宽度而不响应定义的宽度,怎么了?

javascript - 使用 Google Drive API 上传大文件

javascript - 鼠标悬停时关闭下拉菜单的 jQuery 插件

html - 不透明度的 CSS 过渡不起作用

javascript - 水平滚动图像缩略图并在鼠标悬停时弹出图像

html - 类不存在时如何选择选择器