2016-08-01 114 views
0

我试图复制导航按钮here,这是一个wix网站,因此很难检查元素。CSS:带阴影效果的圆形按钮

我试图在这里

https://jsfiddle.net/1vngy4uo/1/

我想很多变化,从来没有得到CSS 100%正确。

.navButton { 
    width:15%; 
    display:inline-block; 
    position:relative; 
    background-color:#03314b; 
    border-radius: 30%; 
    box-shadow: 2px 2px 2px #888888; 
} 
.navButton:hover { 
    background-color:#98b7c8; 
} 
.navButton span { 
    width:100%; 
    display:inline-block; 
    position:absolute; 
    border-radius: 30%; 
    box-shadow: 2px 2px 2px #888888; 
} 
.navButton .bg { 
    height:50%; 
    top:0; 
    background-color:#3a6076 ; 
    border-radius: 30%; 
    box-shadow: 2px 2px 2px #888888; 
} 
.navButton:hover .bg{ 
    background-color:#afcad9; 

} 
.navButton .text { 
    position:relative; 
    text-align:center; 
    color:#fff; 
    vertical-align: middle; 
    align-items: center; 
} 
.navButton .text:hover { 
    color:#000000; 
} 

和HTML

<a href="contact.html" class="navButton"> 
    <span class="bg"></span> 
    <span class="text">Contact</span> 
+0

https://jsfiddle.net/rum5mtnw/ –

+0

https://jsfiddle.net/9L60y8c6/2/ –

+0

网站生成的地点并不重要 - 检查网站的元素是一样的。你总是可以期待有一个应用了CSS的HTML元素。在您引用的网站中,他们使用的是背景图片和其他CSS - 通过检查它很容易看到。 –

回答

1

一个非常类似的一个,使用linear-gradient少HTML标记

jsFiddle

.navButton { 
 
    color: white; 
 
    text-decoration: none; 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    font-size: 14px; 
 
    text-align: center; 
 
    padding: 0 30px; 
 
    line-height: 30px; 
 
    display: inline-block; 
 
    position: relative; 
 
    border-radius: 20px; 
 
    background-image: linear-gradient(#335b71 45%, #03324c 55%); 
 
    box-shadow: 0 2px 2px #888888; 
 
    transition: color 0.3s, background-image 0.5s, ease-in-out; 
 
} 
 
.navButton:hover { 
 
    background-image: linear-gradient(#b1ccda 49%, #96b4c5 51%); 
 
    color: #03324c; 
 
}
<a href="contact.html" class="navButton">Contact</a>

+0

不错......一方面虽然,但在IE9不起作用 – LGSon

+0

谢谢,你当然是对的,但是IE9的使用率是0.43%,IE8是0.63%,所以IE8会让我更害怕:),也可以用<! - [if lte IE 9]>规则修复它一个图像或':before'和':after'作为pollyfill –

+0

我在我的答案中做了':before' ...并且使用百分比取决于您检查的位置,因为现实对于IE9并不是那么糟糕,但是同意, IE8有更高的使用率,我的回答也解决了这个问题:) – LGSon

1

这将是一个开始?你可能想调整一下颜色。

注:一个可以使用的线性渐变,但它不会在IE9工作,所以我用一个伪代替

.navButton { 
 
    width: 15%; 
 
    display: inline-block; 
 
    position: relative; 
 
    background-color: #03314b; 
 
    border-radius: 8px; 
 
    box-shadow: 2px 2px 2px #888888; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    color: #fff; 
 
    padding: 5px; 
 
    transition: all 0.3s; 
 
    overflow: hidden; 
 
} 
 
.navButton:before { 
 
    content: ''; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    height: 50%; 
 
    width: 100%; 
 
    background-color: #335b71; 
 
    transition: all 0.3s; 
 
} 
 
.navButton span { 
 
    position: relative; 
 
} 
 
.navButton:hover { 
 
    transition: all 0.3s; 
 
    background-color: #96b4c5; 
 
    color: black; 
 
} 
 
.navButton:hover:before { 
 
    transition: all 0.3s; 
 
    background-color: #b1ccda; 
 
}
<a href="contact.html" class="navButton"> 
 
    <span>Contact</span> 
 
</a>

1

我只是用一个div元素实现您提到的相同按钮。这是你想要的吗?

https://jsfiddle.net/9L60y8c6/

<div class="test"> 

</div> 

.test { 
    cursor: pointer; 
    background: rgba(4, 53, 81, 1) url(//static.parastorage.com/services/skins/2.1212.0/images/wysiwyg/core/themes/base/shiny1button_bg.png) center center repeat-x; 
    border-radius: 10px; 
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); 
    transition: background-color 0.4s ease 0s; 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 5px; 
    right: 5px; 
    height: 30px; 
    width: 115px; 
} 
+0

https://jsfiddle.net/9L60y8c6/2/ –