2015-02-06 77 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