下面就是幾個(gè)糖果按鈕的效果圖氧骤,在這里把它們分享給大家呻疹,沒(méi)有使用圖片,是純CSS3編寫(xiě)的语淘,在實(shí)際項(xiàng)目中我們應(yīng)盡量避免使用過(guò)多的圖片诲宇,以減輕瀏覽器的負(fù)擔(dān)际歼。那么關(guān)于這個(gè)問(wèn)題,CSS3的出現(xiàn)無(wú)疑幫了我們一個(gè)很大的忙姑蓝,并且將來(lái)CSS3所帶來(lái)的兼容性問(wèn)題也只會(huì)越來(lái)越少鹅心。
糖果按鈕
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">點(diǎn)擊這里</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; }
/* 藍(lán)色 */
.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;
}
這里只是一個(gè)例子, 并非所有瀏覽器都支持纺荧。 希望這些CSS3代碼能夠給您一些啟發(fā)旭愧,讓您能夠打開(kāi)思維,收獲更多宙暇。