0

My HTML is like below

<li class="category">Hair</li>

My CSS code is like below

.category:hover:after {
    position: absolute;
    content: "\f054" !important;
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    right: 18px;
    top: 15px;
    font-size: 18px;
    color: #ff0052;
}

When I hover on Hair, color is not changing to #ff0052.

10
  • 3
    remove the :after Commented Sep 13, 2020 at 12:02
  • 1
    Also no need of position: absolute;. Commented Sep 13, 2020 at 12:04
  • 1
    remove right: 18px; .. Commented Sep 13, 2020 at 12:04
  • 2
    you want to change the color of :after on hover, right? Commented Sep 13, 2020 at 12:04
  • 2
    Yeah, true. Figured this aswell, might use ::after instead of :after, see here: codepen.io/SimplyCius/pen/JjXZjPm Commented Sep 13, 2020 at 12:10

1 Answer 1

1

.category {
   position: relative;
   cursor: pointer;
}
.category:hover{
   color: red !important;
}

.category:hover::after {
   content: "++";
    position: absolute;
    font-weight: 900;
    top: 15px;
    font-size: 18px;
    color: red !important;
}
<li class="category">Hair</li>

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @Abdulah Al Noor. But I need to change the color of Hair also. Thanks.
Thanks @Abdullah Al Noor. I would like to avoid this portion .category:hover{ color: red !important; }.
@abuabu i did not understand .. what do you want actually ?
Actually I did like you before. But I would like to avoid .category:hover{ color: red !important; }. Is possible to get same functionality without that portion ? Thanks.
::after and li.category are two separate element ... i think it's not possible ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.