2016-08-01 52 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/ –