如果將鼠標懸停在元素上,則轉換可以工作,但不會在離開元素時轉換。我該如何解決它?僞元素轉換
這是我的代碼和我JSFiddle
.block{
border: 2px solid grey;
border-radius: 4px;
height: 90px;
margin: 0 auto;
text-align: center;
width: 110px;
padding-top: 6px;
}
.fr:hover{
-webkit-transition: all 0.4s ease 0s;
-moz-transition: all 0.4s ease 0s;
-ms-transition: all 0.4s ease 0s;
-o-transition: all 0.4s ease 0s;
transition: all 0.4s ease 0s;
position: relative;
\t border-top: 2px solid rgba(150, 200, 200, 1);
\t border-bottom: 2px solid rgba(0, 0, 0, 1);
}
.fr:before, .fr:after {
-webkit-transition: opacity 0.2s ease-in-out;
-moz-transition: opacity 0.2s ease-in-out;
-ms-transition: opacity 0.2s ease-in-out;
-o-transition: opacity 0.2s ease-in-out;
transition: opacity 0.2s ease-in-out;
content: "";
position: absolute;
background-image: linear-gradient(to bottom, rgba(150, 200, 200, 1) 0%, rgba(10, 20, 20, 1) 80%), linear-gradient(to bottom, rgba(150, 200, 200, 1) 10%, rgba(10, 20, 20, 1) 100%);
opacity: 0;
}
.fr:hover:before, .fr:hover:after {
-webkit-transition: opacity 0.2s ease-in-out;
-moz-transition: opacity 0.2s ease-in-out;
-ms-transition: opacity 0.2s ease-in-out;
-o-transition: opacity 0.2s ease-in-out;
transition: opacity 0.2s ease-in;
content: "";
position: absolute;
background-image: linear-gradient(to bottom, rgba(155, 200, 200, 1) 0%, rgba(10, 20, 20, 1) 80%), linear-gradient(to bottom, rgba(155, 200, 200, 1) 10%, rgba(10, 20, 20, 1) 100%);
top: 0px; bottom: 0px; width: 2px;
opacity: 1;
}
.fr:before { left: -2px; }
.fr:after { right: -2px; }
<div class="block fr"></div>
將'transition'屬性移出':hover'選擇器,並移動到'.block'或'.fr'。 – Sampson
Hello Sampson,謝謝你的迴應。它適用於頂部和底部欄,但不適用於僞元素(左側和右側欄)。 – Rafael
你能告訴我開始和結束狀態應該是什麼樣子嗎? – Sampson