Home >Web Front-end >CSS Tutorial >Why Doesn't My CSS Hover Code Underline My Link?
When working with CSS, 'hover' is a crucial concept for modifying element styles upon mouse interaction. However, achieving the desired outcome requires correct implementation.
Recently, a query arose regarding the inability of the following code to underline a link upon hover:
<a class="hover">click</a> a .hover:hover { text-decoration: underline; }
To rectify the issue, we must remember that 'hover' is a pseudo-element. The correct syntax is:
a:hover { text-decoration: underline; }
Alternatively, if a class-name is preferred:
a.hover:hover { text-decoration: underline; }
While using a class-name like 'hover' may seem redundant, it can be applied in situations where you want to toggle multiple properties upon hover by utilizing a separate CSS rule for '.hover'. However, if the sole intent is to underline a link on hover, the a:hover selector remains the preferred choice.
The above is the detailed content of Why Doesn't My CSS Hover Code Underline My Link?. For more information, please follow other related articles on the PHP Chinese website!