我想我有一些错误,我的眼睛无法找到问题。所以我要求你帮助我找到我的问题 - 强调不要出现在悬停中。
你可以通过fidle net slash找到t4fmuxbL(因为这个愚蠢的编辑器)
body, div, span, ul, li {
margin:0;
padding:0;
font-family:"Agency FB";
}
li, a {
list-style-type:none;
text-decoration:none;
color:white;
font-size:14px;
}
li {
display:inline-block;
margin:28.5px 5px 5px 35px;
}
.underline-div {
border-top:3px solid #FFB700;
width:12px;
float:left;
margin-left:41px;
margin-top:-3px;
display:none;
}
#und-div2 {
margin-left:56px;
width:22px;
}
#und-div3 {
margin-left:56px;
width:18px;
}
#und-div4 {
margin-left:55px;
width:36px;
}
#news:hover #und-div1 {
display:block;
}
#forums:hover #und-div2 {
display:block;
}
#blogs:hover #und-div3 {
display:block;
}
#statistics:hover #und-div4 {
display:block;
}
.page, .header {
padding:0;
}
.page {
border:1px solid black;
height:1200px;
min-width:1265px;
width:100%;
}
.header-bg {
height:655px;
border:1px solid black;
background:url("http://pokkers.lv/photo-bg.jpg");
background-size:cover;
}
nav {
display:block;
width:100%;
height:75px;
background-color:rgba(0,0,0,0.2);
}
.main-nav {
width:380px;
height:75px;
}
.left-nav{
margin-left:200px;
position:absolute;
top:0;
}
.right-nav {
margin-right:200px;
float:right;
}
.side-div {
border:1px solid white;
}
<body>
<div class = "col-md-12 page">
<header class = "col-md-12 header">
<div class = "header-bg">
<nav>
<div class = "left-nav main-nav">
<ul>
<li id = "news"><a href = "#">NEWS</a></li>
<li id = "forums"><a href = "#">FORUMS</a></li>
<li id = "blogs"><a href = "#">BLOGS</a></li>
<li id = "statistics"><a href = "#">STATISTICS</a></li>
</ul>
<div class = "underline-div" id = "und-div1"> </div>
<div class = "underline-div" id = "und-div2"> </div>
<div class = "underline-div" id = "und-div3"> </div>
<div class = "underline-div" id = "und-div4"> </div>
</div>
<div class = "right-nav main-nav">
<ul>
<li><a href = "#">SERVERS</a></li>
<li><a href = "#">BANLIST</a></li>
<li><a href = "#">MARKET</a></li>
<li><a href = "#">CONTACTS</a></li>
</ul>
</div>
</nav>
</div>
</header>
</div>
</body>
答案 0 :(得分:1)
你必须添加 文字装饰:下划线; 悬停物品
答案 1 :(得分:0)
我不太清楚为什么你使用新的<div>
元素作为下划线,但要明白这一点:
无法在当前的HTML结构中选择悬停的div。
为什么不在悬停时向初始text-decoration: underline
添加简单的<li>
?然后,您可以简单地解决<a>
标记,我在此更新了您的代码:
body, div, span, ul, li {
margin:0;
padding:0;
font-family:"Agency FB";
}
li, a {
list-style-type:none;
text-decoration:none;
color:white;
font-size:14px;
}
li {
display:inline-block;
margin:28.5px 5px 5px 35px;
}
li a:hover {
border-bottom:3px solid #FFB700;
}
.page, .header {
padding:0;
}
.page {
border:1px solid black;
height:1200px;
min-width:1265px;
width:100%;
}
.header-bg {
height:655px;
border:1px solid black;
background:url("http://pokkers.lv/photo-bg.jpg");
background-size:cover;
}
nav {
display:block;
width:100%;
height:75px;
background-color:rgba(0,0,0,0.2);
}
.main-nav {
width:380px;
height:75px;
}
.left-nav{
margin-left:200px;
position:absolute;
top:0;
}
.right-nav {
margin-right:200px;
float:right;
}
.side-div {
border:1px solid white;
}
<body>
<div class = "col-md-12 page">
<header class = "col-md-12 header">
<div class = "header-bg">
<nav>
<div class = "left-nav main-nav">
<ul>
<li id = "news"><a href = "#">NEWS</a></li>
<li id = "forums"><a href = "#">FORUMS</a></li>
<li id = "blogs"><a href = "#">BLOGS</a></li>
<li id = "statistics"><a href = "#">STATISTICS</a></li>
</ul>
</div>
<div class = "right-nav main-nav">
<ul>
<li><a href = "#">SERVERS</a></li>
<li><a href = "#">BANLIST</a></li>
<li><a href = "#">MARKET</a></li>
<li><a href = "#">CONTACTS</a></li>
</ul>
</div>
</nav>
</div>
</header>
</div>
</body>
答案 2 :(得分:0)
以下是一个如何使用以下内容完成此操作的示例:在伪元素之后,因为您拥有的当前HTML结构将不允许您将鼠标悬停在链接上,并显示一个div(或任何其他元素)是<a>
CSS:
.main-nav a {
position: relative;
text-decoration: none
}
.main-nav a:after {
content: '';
display: none;
height: 2px;
background: #f00;
width: 100%;
bottom: 0px;
left: 0px;
position: absolute;
}
.main-nav a:hover:after,
.main-nav a:focus:after {
display: block;
}
演示HTML
<ul class="main-nav">
<li>
<a href="#!">
Link
</a>
</li>
</ul>