简体   繁体   English

在悬停效果上设置文本装饰下划线

[英]Set text-decoration underline on hover effect

I have a html 我有一个HTML

<div class="col store">
 <h4>POLICIES</h4>
  <ul>
     <li><a href="#">Shipping Policies</a></li>
     <li><a href="#">Return Policy</a></li>
     <li><a href="#">Privacy Policy</a></li>
     <li><a href="#">Terms of Use</a></li>
     <li><a href="#">Blog</a></li>
     <li><a href="#">How To Shop</a></li>
  </ul>
</div>

I want the a href to get underlined when hovered. 我希望将href悬停时加下划线。

I have used this css, but still it isn't happening. 我已经使用过此CSS,但仍然没有发生。

.col .about ul li a:hover
{
   text-decoration: underline;
}

.col element doesn't have any .about descendants, so the selector simply fails! .col元素没有任何.about后代,因此选择器只会失败! You should remove the .about part. 您应该删除.about部分。

Check following you updated code: 检查以下更新的代码:

 .col ul li a:hover { text-decoration: underline; } .col ul li a{ text-decoration: none; } 
 <div class="col store"> <h4>POLICIES</h4> <ul> <li><a href="#">Shipping Policies</a></li> <li><a href="#">Return Policy</a></li> <li><a href="#">Privacy Policy</a></li> <li><a href="#">Terms of Use</a></li> <li><a href="#">Blog</a></li> <li><a href="#">How To Shop</a></li> </ul> </div> 

The css you pasted is not matching the markup in the page, so the solution to this is to rewrite your css by removing the missing markup element .about 您粘贴的css与页面中的标记不匹配,因此解决方案是通过删除缺少的标记元素.about来重写css。

.col ul li a:hover
{
   text-decoration: underline;
}

You only need to reference the class "col", then the "a" tag. 您只需要引用类“ col”,然后引用“ a”标签。

 .col a{ color:red; text-decoration:none; } .col a:hover{ text-decoration:underline; color:blue; } 
 <div class="col store"> <h4>POLICIES</h4> <ul> <li><a href="#">Shipping Policies</a></li> <li><a href="#">Return Policy</a></li> <li><a href="#">Privacy Policy</a></li> <li><a href="#">Terms of Use</a></li> <li><a href="#">Blog</a></li> <li><a href="#">How To Shop</a></li> </ul> </div> 

http://jsfiddle.net/ofsmnp8y/ Set your link preferences before hover, then set the preferences for hover, as shown in the example. http://jsfiddle.net/ofsmnp8y/在悬停之前设置链接首选项,然后为悬停设置首选项,如示例所示。

Please be aware you can also use :active, :link, :hover, :visited, and you will have to style these appropriately. 请注意,您也可以使用:active,:link,:hover,:visited,并且必须适当设置样式。

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

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