简体   繁体   English

如何在CSS中的悬停链接上创建下划线效果

[英]How to create underline effect on hovered links in css

The styling I look into achieving can be shown in this screenshot: 我希望实现的样式可以在以下屏幕截图中显示: .

Please tell how to create the effect that i pointed out using CSS. 请告诉我如何使用CSS指出效果。

By using :hover and setting a border-bottom . 通过使用:hover并设置border-bottom Something like this 像这样

 ul{ list-style: none; padding: 0; margin: 0; } ul li{ float: left; margin: 0 5px; } ul li a{ text-decoration:none; color: black; } ul li:hover{ border-bottom: 2px solid red; } 
 <ul> <li><a href="">Home</a></li> <li><a href="">About</a></li> <li><a href="">Contact</a></li> </ul> 

  a { display: inline-block; position: relative; text-decoration: none; text-align: center; } a:hover:before { content: ''; width: 100%; height: 100%; position: absolute; left: 0; bottom: 0; box-shadow: inset 0 -10px 0 #11c0e5; } a span { display: block; width: 100px; height: 40px; background-color: red; padding-top: 20px; } 
  <a href="#"> <span>link texts</span> </a> 

a{
   text-decoration:none;
}

a:hover {
   text-decoration:underline;
}

This should work for links, however the effect in the picture seems to be made with the link's container border: 这应该适用于链接,但是图片中的效果似乎是由链接的容器边框产生的:

div.yourcontainer:hover{
    border-bottom:2px solid red;
}

This should work ^^ 这应该工作^^

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM