【发布时间】:2020-10-17 13:55:46
【问题描述】:
我有一个由两部分组成的导航栏。左侧是徽标图片。右侧栏由 4 个列表元素组成。我希望一个三角形出现在悬停元素的底部。我将列表浮动到右侧。现在我尝试了前后的伪类元素。但是三角形固定在任何悬停的元素上。我尝试更改所有参数,但随后整个条形都发生了变化。
<html>
<head>
<meta name="viewport"
content="width=device-width, initial-scale=1">
<style>
#navlist {
background-color: black;
position: absolute;
width: 100%;
padding-bottom: 0 px;
}
#navlist a {
float:left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 10px;
text-decoration: none;
font-size: 15px;
margin-bottom: 0px;
outline: none;
}
.navlist-right a:hover:before {
content: "";
position: absolute;
top: 40px;
left: 50%;
margin-left: -15px;
width: 0px;
height 0px;
xxmargin: 0px auto;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-bottom: 15px solid black;
}
.navlist-right a:hover:after {
content: "";
position: absolute;
top: 40px;
left: 50%;
margin-left: -15px;
width: 0px;
height 0px;
xxmargin: 0px auto;
border-left: 12px solid transparent;
border-right: 12px solid transparent;
border-bottom: 12px solid white;
}
.navlist-right{
width:20%;
float:right;
font-weight: bolder;
padding-bottom: 0 px;
}
#navlist a:hover {
color : #f2f2f2;
}
</style>
</head>
<body>
<!-- Navbar items -->
<div id="navlist">
<ul>
<li class="navlist-left">
<a href="#">
<span class="span-logo">
<img src="/home/sahanaswamy/Downloads/logo.png" />
</span>
</a>
</li>
</ul>
<div class="navlist-right">
<a href="#">Home</a>
<a href="#">Work</a>
<a href="#">Us</a>
<a href="#">Contact</a>
</div>
</div>
</body>
</html>
我应该更改任何 before after 属性吗?如果我尝试更改悬停元素中的顶部和左侧属性,三角形将最终处于固定状态。
【问题讨论】:
标签: html css css-selectors pseudo-element