简体   繁体   English

当我将鼠标悬停在导航栏中的链接上时,如何创建下划线?

[英]How do I create an underline when I hover over links in nav bar?

I want to create an underline when I hover over the links in my navigation bar. 当我将鼠标悬停在导航栏中的链接上时,我想创建一个下划线。 I'm not sure which id I should be targeting. 我不确定我应该针对哪个ID。 Here's my JFiddle: https://jsfiddle.net/gzycz4h8/ 这是我的JFiddle: https ://jsfiddle.net/gzycz4h8/

Thanks in advance. 提前致谢。

<ul id="nav">
  <li><a href="#">About</a></li>
  <li><a href="#">Writing</a></li>
  <li><a href="#">Multimedia</a></li>
  <li><a href="#">Resume</a></li>
  <li><a href="#">Contact</a></li>
</ul>

are you looking for something like this ? 你在找这样的东西吗?

#nav {
  padding: 10px 0;
  width:700px;
  margin: 0 auto;
  text-align: center;
  list-style-type: none;
  display:block;
  text-decoration: none;
  -webkit-box-shadow: 0 2px 10px -12px #999;
  -moz-box-shadow: 0 8px 6px -6px #999;
   box-shadow: 0 8px 6px -6px #999;
}

#nav li {
  display: inline-block;
  margin: 5px;
  text-transform: uppercase;

}
#nav li a {
  text-decoration:none;
}
#nav li a:hover {
    text-decoration: underline;
    text-decoration-color: black;
    -o-transition:.4s;
    -ms-transition:.4s;
    -moz-transition:.4s;
    -webkit-transition:.4s;
    transition:.4s;

}

Or something like this: https://jsfiddle.net/m16gggk1/1/ 或类似的东西: https//jsfiddle.net/m16gggk1/1/

#nav {
  padding: 0;
  width:700px;
  margin: 0 auto;
  text-align: center;
  list-style-type: none;
  display:block;
  text-decoration: none;
  -webkit-box-shadow: 0 2px 10px -12px #999;
  -moz-box-shadow: 0 8px 6px -6px #999;
   box-shadow: 0 8px 6px -6px #999;
}

#nav li {
  display: inline-block;
  margin: 0 5px;
  text-transform: uppercase;
  border-bottom:2px solid #fff;

}
#nav li a {
  text-decoration:none;
}
#nav li a:hover {
  color:red;
}
#nav li:hover {
    border-bottom:2px solid red;


}

The most simple solution would be: 最简单的解决方案是:

li a {
  text-decoration:none;
}

li a:hover {
    text-decoration: underline;
}

https://jsfiddle.net/LvLsckzw/ https://jsfiddle.net/LvLsckzw/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改导航栏链接悬停和活动状态 - how do I change nav bar links hover and active state 如何从Bootstrap主题中移除悬停导航下划线? - How do I remove nav underline on hover from Bootstrap theme? 当用户在导航栏上突出显示网页文本时,如何添加下划线颜色? - How can I add an underline colour when the user highlights over the webpage text on nav bar? 如何在导航栏中获取我的导航链接? - How do I get my nav links in the nav bar? 将鼠标悬停在导航栏中时,如何在文本后面填充背景? [HTML / CSS] - How can I fill in the background behind text when I hover over it in a nav bar? [HTML/CSS] 当我向上滚动并在向上滚动或当我将鼠标悬停在上面时,如何使导航条变得透明? - How do i make my nav bar transparent when I scroll down and come back when I scroll up or when I hover my mouse over is? 当我将鼠标悬停在导航菜单上时,它会将内容下推,为什么? 悬停时如何更改li的颜色? - When I hover over my nav menu it pushes content down, why? How do i change color of li when hover over? 如何仅在选定的导航上进行悬停效果 - How do I make the hover effect over only the selected nav 如何在导航栏中平均间隔链接? - How do I space out the links equally in a nav bar? 将鼠标悬停在特定的导航链接上时,如何交换具有不同徽标的页面徽标 - How Do I Swap Page Logo With Different Logo When Hovering Over Specific Nav Links
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM