2015-02-06 80 views
1

只是想知道是否有任何人有解決問題的經驗,我已經使用按鈕的3D效果懸停狀態。3D效果按鈕懸停狀態CSS(可能的錯誤?)

http://jsfiddle.net/andeh/b47xor6d/

.button{ 
cursor: pointer; 
display: block; 
line-height: 44px; 
height: 44px; 
width: 159px; 
background: #ff9600; 
border-radius: 5px; 
text-align: center; 
font-size: 18px; 
color: #fff; 
} 
.button:hover { 
display: block; 
min-height: 44px; 
min-width: 159px; 
background: #e68700; 
border-radius: 5px; 
text-align: center; 
font-size: 18px; 
border: 0 solid #fff; 
color: #fff; 
position: relative; 
top: -5px; 
bottom: auto; 
left: -5px; 
right: auto; 
cursor: pointer; 
background: #e68700; 
box-shadow: #c2c2c2 1px 1px, #c2c2c2 2px 2px, #c2c2c2 3px 3px, #c2c2c2 4px 4px, #c2c2c2 5px 5px; 
} 

正如你可以在我的例子中看到的,是什麼問題,就是當你將鼠標懸停在該按鈕時,如果你的光標上的影子,然後懸停狀態將停用。 據我所知,這是因爲我本質上將按鈕從光標移開,但我認爲創建的陰影可能會如何保留懸停狀態?

如果任何人知道任何修復將是偉大的!但在當下它只是一種刺激而已。

謝謝!

安迪

+0

您使用的效果的盒子陰影。一個影子。即就像在說'在這裏,你站在我身上嗎?'而有人站在你的身後。 – jbutler483 2015-02-06 15:04:48

+0

@ jbutler483你有不同的方法,廣泛兼容? – 2015-02-06 17:40:57

回答

1

我有不同的方法,只需設置box-shadowinset,因此陰影將位於按鈕內部,並且在懸停在陰影上時不會鬆開懸停狀態。你

還需要懸停添加更具體border-radius所以它看起來像一個外部陰影..看到這個http://jsfiddle.net/b47xor6d/3/

.button:hover { 
    display: block; 
    min-height: 44px; 
    height:49px; 
    width: 164px; 
    min-width: 159px; 
    background: #e68700; 
    border-radius: 5px; 
    text-align: center; 
    font-size: 18px; 
    border: 0 solid #fff; 
    color: #fff; 
    position: relative; 
    border-top-right-radius: 10px; 
border-bottom-left-radius: 10px; 
    top: -5px; 
    bottom: auto; 
    left: -5px; 
    right: auto; 
    cursor: pointer; 
    background: #e68700; 
    box-shadow:inset #c2c2c2 -1px -1px,inset #c2c2c2 -2px -2px,inset #c2c2c2 -3px -3px,inset #c2c2c2 -4px -4px,inset #c2c2c2 -5px -5px; 
} 
+0

插圖!這麼簡單...我知道會有一個簡單的解決方案! 謝謝 – 2015-02-06 17:34:41

1

.button{ 
 
    cursor: pointer; 
 
    display: block; 
 
    line-height: 44px; 
 
    height: 44px; 
 
    width: 159px; 
 
    background: #ff9600; 
 
    border-radius: 5px; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    color: #fff; 
 
    transition: transform .3s ease,box-shadow .3s ease 
 
} 
 
.button:hover { 
 
    transform: translate3d(-5px,-5px,0); 
 
    box-shadow: #c2c2c2 1px 1px, #c2c2c2 2px 2px, #c2c2c2 3px 3px, #c2c2c2 4px 4px, #c2c2c2 5px 5px; 
 
}
<span class="button">button</span>

或者試試:speudo元素

.button{ 
 
    display: block; 
 
    position: relative; 
 
    height: 44px; 
 
    width: 159px; 
 
    color: transparent 
 
} 
 
.button:after{ 
 
    content: attr(data-text); 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    line-height: 44px; 
 
    height: 100%; 
 
    width: 100%; 
 
    background: #ff9600; 
 
    border-radius: 5px; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    color: #fff; 
 
    transition: transform .3s ease,box-shadow .3s ease 
 
} 
 
.button:hover:after { 
 
    transform: translate3d(-5px,-5px,0); 
 
    box-shadow: #c2c2c2 1px 1px, #c2c2c2 2px 2px, #c2c2c2 3px 3px, #c2c2c2 4px 4px, #c2c2c2 5px 5px; 
 
}
<span class="button" data-text=button>button</span>

+0

第一個關於鼠標懸停在陰影上的問題仍然存在,但第二個問題確實是一個非常漂亮和優雅的按鈕!我將爲未來的案例存儲,但不幸的是,瀏覽器的兼容性只是沒有translate3d。直到我可以說服我的公司取消對IE8的支持,它只是不是一個選擇:(雖然defo存儲其他項目!它的一個可愛的過渡雖然! – 2015-02-06 17:38:39