Mark Butcher
Mark Butcher

Reputation: 13

CSS Hover control multiple elements differently

The effect I would like to achieve is whether you hover over the "Icon" or the "Title" text that the "Icon" scales, the "Icon" background changes color, and the the "Title" changes color. I do not want the "Title" to scale.

Right now when you hover over the "Title" it has the desired effect, I just can't seem to get the title to change color when you over over the icon area.

Here is the fiddle http://jsfiddle.net/6suqg1mL/.

HTML

<div>
  <a href="#" class="icon-circle">Icon
    <p class="icon-title">Title</p>
  </a>
</div>

CSS

.icon-circle {
  display: block;
  width: 100px;
  height: 100px;
  border-radius: 66px;
  border: 5px solid #000000;
  font-size: 20px;
  color: #000000;
  line-height: 100px;
  text-align: center;
  text-decoration: none;
  background: rgba(0, 0, 0, .1);
  -webkit-transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  -moz-transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  -o-transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
}

.icon-circle:hover {
  border: 5px solid #000000;
  color: blsvk;
  text-decoration: none;
  background: rgba(255, 0, 0, .3);
  font-size: 30px;
  /* ease-in-out */
}    

.icon-title {
  line-height: 20px;
  text-align: center;
  font-size: 40px;
}

.icon-title:hover {
  color: red;
}

Upvotes: 0

Views: 137

Answers (2)

Sarhad Salam
Sarhad Salam

Reputation: 438

I believe this will do it-

  .icon-circle:hover > .icon-title {
      color:red;
    }

Upvotes: 0

Alex
Alex

Reputation: 8695

You can use this .icon-circle:hover .icon-title selector when user hover over the .icon-circle then change the color of .icon-title.

.icon-circle:hover .icon-title {
  color: red; 
}

Jsfiddle

.icon-circle {
  display: block;
  width: 100px;
  height: 100px;
  border-radius: 66px;
  border: 5px solid #000000;
  font-size: 20px;
  color: #000000;
  line-height: 100px;
  text-align: center;
  text-decoration: none;
  background: rgba(0, 0, 0, .1);
  -webkit-transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  -moz-transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  -o-transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  transition: all 700ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
  /* ease-in-out */
}
.icon-circle:hover {
  border: 5px solid #000000;
  color: blsvk;
  text-decoration: none;
  background: rgba(255, 0, 0, .3);
  font-size: 30px;
  /* ease-in-out */
}
.icon-title {
  line-height: 20px;
  text-align: center;
  font-size: 40px;
}
.icon-circle:hover .icon-title {
  color: red;
}
<div>
  <a href="#" class="icon-circle">Icon
<p class="icon-title">Title</p>
</a>
</div>

Upvotes: 1

Related Questions