CSS Hover控制多个元素的方式不同

时间:2015-12-11 04:17:31

标签: html css hover

我想要实现的效果是你是否将鼠标悬停在“图标”或“标题”文本上,“图标”缩放,“图标”背景改变颜色,“标题”改变颜色。我不希望“标题”扩大。

现在,当你将鼠标悬停在“标题”上时,它具有所需的效果,当你翻过图标区域时,我似乎无法获得改变颜色的标题。

这是小提琴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;
}

2 个答案:

答案 0 :(得分:1)

当用户将鼠标悬停在.icon-circle:hover .icon-title上,然后更改.icon-circle的颜色时,您可以使用此.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>

答案 1 :(得分:0)

我相信这会做到 -

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