Home > Software engineering >  I want to change the color of text inside anchor tag when hovered, but CSS doesn't allow refere
I want to change the color of text inside anchor tag when hovered, but CSS doesn't allow refere

Time:09-14

I want to change the text color of anchor tag when hovered on the item, but how can I select anchor tag inside services-list div:hover.

body{
  background: black;
  color: white;
}

.services-list div a {
  text-decoration: none;
  color: #e5f7ef;
  font-size: 12px;
  margin-top: 20px;
  display: inline-block;
}

.services-list div:hover {
  background-color: #43ffaf;
  color: #262a33;
  transform: translateY(-10px);
}
<div >
    <div>
        <p>texts</p>
        <a href="#">Learn More</a>
    </div>
</div>

CodePudding user response:

Also write rule set for anchor tag when hovered.

body{
  background: black;
  color: white;
}

.services-list div a {
  text-decoration: none;
  color: #e5f7ef;
  font-size: 12px;
  margin-top: 20px;
  display: inline-block;
}

.services-list div:hover {
  background-color: #43ffaf;
  color: #262a33;
  transform: translateY(-10px);
}

.services-list div:hover > a {
  color: #262a33;
}
<div >
    <div>
        <p>texts</p>
        <a href="#">Learn More</a>
    </div>
</div>

  • Related