2017-04-10 27 views
-1

如何使用懸停屬性更改字體真棒2次的顏色。懸停屬性如何在CSS中多次工作

.single-post { 
 
    width: 100px; 
 
    height: 100px; 
 
    background:grey; 
 
} 
 

 
.my-link { 
 
    color: white; 
 
} 
 

 
.single-post:hover .my-link { 
 
    color: black; 
 
} 
 

 
.my-link:hover { 
 
    color: red; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> 
 
<div class="single-post"> 
 
    <i class="my-link fa fa-exchange" aria-hidden="true"></i> 
 
</div>

在這裏我無法使它red懸停。

如何改變顏色與懸停第一個黑色,然後紅?

+0

變化'。我的鏈接:hover'到'。單後:懸停。我的鏈接:hover' –

+0

簡短的回答是不能。不像你想的那樣。也許通過CSS轉換,你可能能夠實現你想要的東西。 –

回答

1

我假設你想直接將鼠標懸停在鏈接上並改爲紅色。

.single-post:hover .my-link:hover { 
    color: red; 
} 

代碼片段

.single-post { 
 
    width: 100px; 
 
    height: 100px; 
 
} 
 

 
.my-link { 
 
    color: white; 
 
} 
 

 
.single-post:hover .my-link { 
 
    color: black; 
 
} 
 

 
.single-post:hover .my-link:hover { 
 
    color: red; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> 
 
<div class="single-post"> 
 
    <i class="my-link fa fa-exchange" aria-hidden="true"></i> 
 
</div>

+0

其工作,謝謝 – FRQ6692

+0

酷 - 可能需要批准的答案以及。 *謝謝! –

+0

這是怎麼處理黑色然後紅色?我沒有得到這種效果。 –

2

你可以使用這樣的關鍵幀。

.single-post { 
 
width: 100px; 
 
height: 100px; 
 
background: gray; 
 
} 
 
.my-link { 
 
color: white; 
 
} 
 
.single-post:hover .my-link { 
 
    -webkit-animation: coloranimation 0.5s normal forwards; 
 
    -moz-animation: coloranimation 0.5s normal forwards; 
 
    -o-animation:  coloranimation 0.5s normal forwards; 
 
} 
 
@-webkit-keyframes coloranimation { 
 
    0% {color: white;} 
 
    50% {color: black;} 
 
    100% {color: red;} 
 
} 
 

 
/* Standard syntax */ 
 
@keyframes coloranimation { 
 
    0% {color: white;} 
 
    50% {color: black;} 
 
    100% {color: red;} 
 
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> 
 
<div class="single-post"> 
 
    <i class="my-link fa fa-exchange" aria-hidden="true"></i> 
 
</div>