CSS:具有阴影效果的圆形按钮

时间:2016-08-01 18:26:37

标签: css css3

我试图复制导航按钮here,这是一个wix网站,因此检查元素非常困难。

我试过的是

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>

3 个答案:

答案 0 :(得分: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 :(得分: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;
}

答案 2 :(得分:1)

非常相似,使用linear-gradient和更少的HTML标记

jsFiddle

&#13;
&#13;
.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;
}
&#13;
<a href="contact.html" class="navButton">Contact</a>
&#13;
&#13;
&#13;