TTB*_*BDV 2 html css pseudo-element
我想在将鼠标悬停在列表元素(或者这些列表元素中的锚标记)上时创建过渡效果。
不幸的是,当我使用我创建的转换时,::before 伪元素(或 ::after,我不确定)隐藏了技术上它的同级内容,即锚标记内的文本。
我尝试过操作 ul、li 和 a 标签上的 z-index,但没有成功。问题可能在于我在转换中使用了position:absolute,但我不知道我做错了什么。
这是 HTML 和 CSS 以及JSFiddle 链接
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
#headercontainer {
background-color: #4f2f65;
height: 125px;
position: relative;
}
#headercontainer ul {
height: 100%;
display: table;
text-align: center;
list-style: none;
margin: 0;
padding: 0;
}
#sitelogo {
padding-top: 0px;
}
#headercontainer ul li {
display: table-cell;
vertical-align: middle;
position: relative;
}
#headercontainer ul li a {
color: #fff;
font-size: 20px;
text-decoration: none;
}
a::before {
content: '';
display: block;
height: 0px;
background-color: #fff;
position: absolute;
bottom: 0;
width: 100%;
transition: all ease-in-out 200ms;
}
a:hover::before {
height: 125px;
}
header::after {
content: '';
display: table;
clear: both;
}
#headerlinkslist a:hover {
color: red;
}
.headerlinks {
padding-left: 80px;
padding-right: 80px;
}Run Code Online (Sandbox Code Playgroud)
<body>
<header>
<div id="headercontainer">
<ul id="headerlinkslist">
<li id="sitelogo"></li>
<li><a href="" class="headerlinks">RULES</a></li>
<li><a href="" class="headerlinks">NEWS</a></li>
<li><a href="" class="headerlinks">STATS</a></li>
<li><a href="" class="headerlinks">SUBMIT</a></li>
<li><a href="" class="headerlinks">LOGIN / REGISTER</a></li>
</div>
</header>
</body>Run Code Online (Sandbox Code Playgroud)
给父级lia z-index,然后使用z-index: -1伪元素将其推到 后面a但位于 之上li。
您还需要关闭您的ul
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
#headercontainer {
background-color: #4f2f65;
height: 125px;
position: relative;
}
#headercontainer ul {
height: 100%;
display: table;
text-align: center;
list-style: none;
margin: 0;
padding: 0;
}
#sitelogo {
padding-top: 0px;
}
#headercontainer ul li {
display: table-cell;
vertical-align: middle;
position: relative;
z-index: 1;
}
#headercontainer ul li a {
color: #fff;
font-size: 20px;
text-decoration: none;
transition: color .25s;
}
a::before {
content: '';
display: block;
height: 0px;
background-color: #fff;
position: absolute;
bottom: 0;
width: 100%;
transition: all ease-in-out 200ms;
z-index: -1;
}
a:hover::before {
height: 125px;
}
header::after {
content: '';
display: table;
clear: both;
}
#headerlinkslist a:hover {
color: red;
}
.headerlinks {
padding-left: 80px;
padding-right: 80px;
}Run Code Online (Sandbox Code Playgroud)
<body>
<header>
<div id="headercontainer">
<ul id="headerlinkslist">
<li id="sitelogo"></li>
<li><a href="" class="headerlinks">RULES</a></li>
<li><a href="" class="headerlinks">NEWS</a></li>
<li><a href="" class="headerlinks">STATS</a></li>
<li><a href="" class="headerlinks">SUBMIT</a></li>
<li><a href="" class="headerlinks">LOGIN / REGISTER</a></li>
</ul>
</div>
</header>
</body>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1674 次 |
| 最近记录: |