简体   繁体   English

为什么悬停选择器不适用于小节?

[英]Why hover selector doesn't work with clases?

I have set the styles for links (active, link, etc), but then I want to do a button with totally different styles so I tried something like this: 我已经设置了链接的样式(活动,链接等),但是随后我想用完全不同的样式来做一个按钮,所以我尝试了以下方法:

 .r-button { padding: 4px 52px; display: inline-block; text-align: center; font-size: 16px; text-decoration: none !important; color: black !important; border-radius: 12px; border:1px inset #282c37;} .r-button:hover { cursor: selector; color:ivory;} 
 <a class="r-button" onclick="document.getElementById('menu').style.display='block'"> Click button </a> 

But then I realized that :hover doesn't work with clases. 但是后来我意识到:hover不适用于句号。 Why is that? 这是为什么? What others chances do I have to do the same? 我还必须做些其他的机会吗?

You will need to either REMOVE !important from your color in .r-button or add it to .r-button:hover 's color 您需要从.r-button颜色中删除!important或将其添加到.r-button:hover的颜色中

 .r-button { padding: 4px 52px; display: inline-block; text-align: center; font-size: 16px; text-decoration: none !important; color: black !important; border-radius: 12px; border:1px inset #282c37;} .r-button:hover { cursor: selector; color:ivory !important;} 
 <a class="r-button" onclick="document.getElementById('menu').style.display='block'"> Click button </a> 

It does, your color: black !important; 它的color: black !important;您的color: black !important; is overriding the hover and that selector isn't a valid cursor. 正在覆盖悬停,并且selector不是有效的游标。 Try pointer on hover. 尝试将鼠标悬停。

.r-button:hover { cursor: pointer; }

Your :hover pseudo element was being overwritten with !important . 您的:hover伪元素已被!important覆盖。 Avoid using !important rules within your default class. 避免在默认类中使用!important规则。

Bonus tip! 奖金提示! Remove cursor: pointer for anchor tags, and simply have an empty href="#" attribute for better accessibility. 删除cursor: pointer锚标记的cursor: pointer ,只需具有一个空的href="#"属性,以实现更好的可访问性。

 .r-button { padding: 4px 52px; display: inline-block; text-align: center; font-size: 16px; text-decoration: none; color: black; border-radius: 12px; border: 1px inset #282c37; } .r-button:hover { background-color: #282c37; color: ivory; } 
 <a class="r-button" href="#" onclick="document.getElementById('menu').style.display='block'">Click button</a> 

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

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