CSS3:分享几个糖果按钮实例
2019-08-04 本文已影响13人
LXEP
下面就是几个糖果按钮的效果图,在这里把它们分享给大家,没有使用图片,是纯CSS3编写的,在实际项目中我们应尽量避免使用过多的图片,以减轻浏览器的负担。那么关于这个问题,CSS3的出现无疑帮了我们一个很大的忙,并且将来CSS3所带来的兼容性问题也只会越来越少。
糖果按钮index.html:
<a href="#" class="button">按钮</a>
<a href="#" data-icon="✂" class="button blue brackets">截取</a>
<a href="#" data-icon="☞" class="button pink serif skew">点击这里</a>
<a href="#" data-icon="&" title="Reddit" class="button green serif back xl glass icon"></a>
<a href="#" data-icon="☀" class="button green disabled">天气</a>
<a href="#" data-icon="✌" title="Love" class="button pink oval icon"></a>
<a href="#" data-icon="☃" title="Quit" class="button orange shield xl icon"></a>
<a href="#" data-icon="⌚" title="Upload" class="button blue back xl glass icon"></a>
<a href="#" data-icon="▶" title="RSS" class="button orange drop glass icon"></a>
index.css
.button {
position: relative;
display: inline-block;
text-decoration: none;
font: 24px/1em 'Droid Sans', sans-serif;
font-weight: bold;
text-shadow: rgba(255,255,255,.5) 0 1px 0;
user-select: none;
padding: .5em .6em .4em .6em;
margin: .5em;
border-radius: 8px;
border-top: 1px solid rgba(255,255,255,0.8);
border-bottom: 1px solid rgba(0,0,0,0.1);
transition: background .2s ease-in-out;
color: #666666 !important;
background-color:#c0c0c0;
box-shadow: inset #fffeff 0 0.3em .3em, inset rgba(0,0,0,0.15) 0 -0.1em .3em,
#999999 0 .1em 3px, #737373 0 .3em 1px,
rgba(0,0,0,0.2) 0 .5em 5px;
}
.button:before {
font: 1.2em/0 sans-serif;
content: attr(data-icon);
margin-right: 6px;
}
.icon {
font-weight: normal;
font-style: normal;
}
.icon:before {
display: block;
height: .75em;
line-height: .75em;
margin: 0;
}
/* 橙色 */
.button.orange {
color:#996700 !important;
background-color:#ffa600;
box-shadow: inset rgba(255,254,255,0.6) 0 0.3em .3em, inset rgba(0,0,0,0.15) 0 -0.1em .3em,
#cc8500 0 .1em 3px, #996400 0 .3em 1px,
rgba(0,0,0,0.2) 0 .5em 5px;
}
.button.orange:hover { background-color: #ffc14d; }
/* 蓝色 */
.button.blue {
color:#336a9a !important;
background-color:#80c4ff;
box-shadow: inset rgba(255,254,255,0.6) 0 0.3em .3em, inset rgba(0,0,0,0.15) 0 -0.1em .3em,
#5391c6 0 .1em 3px, #336a9a 0 .3em 1px,
rgba(0,0,0,0.2) 0 .5em 5px;
}
.button.blue:hover { background-color: #a9d7ff; }
/* 绿色 */
.button.green {
color: #518317 !important;
background-color: #9ee152;
box-shadow: inset rgba(255,254,255,0.6) 0 0.3em .3em, inset rgba(0,0,0,0.15) 0 -0.1em .3em,
#6bae1f 0 .1em 3px, #518317 0 .3em 1px,
rgba(0,0,0,0.2) 0 .5em 5px;
}
.button.green:hover { background-color: #c3ec93; }
/* 粉色 */
.button.pink {
color: #990033 !important;
background-color: #ff80aa;
box-shadow: inset rgba(255,254,255,0.6) 0 0.3em .3em, inset rgba(0,0,0,0.15) 0 -0.1em .3em,
#d92762 0 .1em 3px, #b8154b 0 .3em 1px,
rgba(0,0,0,0.2) 0 .5em 5px;
}
.button.pink:hover { background-color: #ffa9c6; }
.button:hover {
background-color: #d4d4d4;
}
.button:active {
background-image: gradient(radial, 50% 0, 100, 50% 0, 0, from( rgba(255,255,255,0) ), to( rgba(255,255,255,0) )), url(noise.png);
box-shadow: inset rgba(255,255,255,0.6) 0 0.3em .3em, inset rgba(0,0,0,0.2) 0 -0.1em .3em,
rgba(0,0,0,0.4) 0 .1em 1px,
rgba(0,0,0,0.2) 0 .2em 6px;
transform: translateY(.2em);
}
.button:focus {
outline: none;
color: rgba(254,255,255,0.9) !important;
text-shadow: rgba(0,0,0,0.2) 0 1px 2px;
}
.button[disabled], .button[disabled]:hover, .button.disabled, .button.disabled:hover {
opacity: .5;
cursor: default;
color:rgba(0,0,0,0.2) !important;
text-shadow: none !important;
background-color:rgba(0,0,0,0.05);
background-image: none;
border-top: none;
box-shadow: inset rgba(255,254,255,0.4) 0 0.3em .3em, inset rgba(0,0,0,0.1) 0 -0.1em .3em,
rgba(0,0,0,0.3) 0 .1em 1px,
rgba(0,0,0,0.2) 0 .2em 6px;
transform: translateY(5px);
}
.serif {
font-family: 'Lobster', serif;
font-weight: normal;
}
.xl {font-size: 32px;}
.button.icon.glass:after { height: 75% ; }
.button.glass {
text-shadow:rgba(255,255,255,.5) 0 -1px 0, rgba(0,0,0,0.18) 0 .18em .15em;
}
.button.glass:active {
text-shadow:rgba(255,255,255,.3) 0 1px 0, rgba(0,0,0,0.15) 0 .18em .15em;
}
.oval {
border-top: none;
padding-left: .8em;
padding-right: .8em;
border-radius: 5em / 2em;
}
.oval.icon {
padding-left: .8em;
padding-right: .8em;
border-radius: 1.5em / 1em;
}
.brackets {
border-top: none;
border-radius: .5em / 1em;
}
.skew {
border-top: none;
padding-right: 1.2em;
padding-left: 0.8em;
border-radius: 5em 1em / 5em 1em;
}
.skew.icon {
padding-right: .9em;
padding-left: .8em;
}
.back {
border-top-color:rgba(255,255,255,0.5);
border-radius: 1.6em 1.6em 1em 1em / 4em 4em 1em 1em;
}
.shield{
border-radius: .4em .4em 2em 2em / .4em .4em 3em 3em;
}
.shield {
padding-left: .8em;
padding-right: .8em;
}
.shield.icon {
padding-left: .6em;
padding-right: .6em;
}
.drop {
border-top: none;
border-radius: 2em 5em 2em .6em / 2em 4em 2em .6em;
}
.drop.icon {
padding-right: .6em;
}
这里只是一个例子, 并非所有浏览器都支持。 希望这些CSS3代码能够给您一些启发,让您能够打开思维,收获更多。