国产精品无码久久久久久,精品久久久久久国产,波多野结衣中文字幕一区二区三区,久久久亚洲欧洲日产国码农村

css3圓角介紹與應(yīng)用技巧

2016/12/7 8:43:06   閱讀:1742    發(fā)布者:1742

*以下技巧均源自于Lea Verou所著《CSS Secrets》

自適應(yīng)橢圓與圓角構(gòu)造

  在css上構(gòu)造圓形只需要將border-radius屬性值設(shè)為邊長(zhǎng)的一半即可。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>border-radius</title> 
    <style> 
        .borderRadius{ 
            display: inline-block; 
            background: #fb3; 
            min-width: 200px; 
            height: 200px; 
            line-height: 200px; 
            border-radius: 100px; /* 邊長(zhǎng)的一半 */ 
            box-sizing: border-box; 
            padding:0 5px; 
        } 
    </style> 
</head> 
<body> 
    <div class="borderRadius"> 
       <div class="innerTxt"></div> 
    </div> 
</body> 
</html>

顯示效果如下:

以上布局當(dāng)我們?cè)趇nnerTxt中添加過多的內(nèi)容時(shí),會(huì)得到如下的效果:

如果我們想要一個(gè)自適應(yīng)的橢圓的話,那么border-radius中就不應(yīng)該是一個(gè)固定的值,
當(dāng)我們將border-radius設(shè)置為50%時(shí),顯示效果如下:

這樣就變成了一個(gè)自適應(yīng)的橢圓了。

這里我們?nèi)娼榻B一下border-radius的屬性,border-radius是一個(gè)簡(jiǎn)寫屬性,
它的展開式是border-top-left-radius、border-top-right-radius、border-bottom-right-radius、border-bottom-left-radius。

它還有一個(gè)鮮為人知的特性:border-radius可以單獨(dú)指定水平和垂直半徑,
只要用一個(gè)斜杠( / )分隔這兩個(gè)值即可
(圓形圓角水平和垂直半徑相等,可以合并)。

結(jié)合這這些特性來看的話,border-radius:50%;的詳細(xì)展開應(yīng)該是border-radius:50% 50% 50% 50%/50% 50% 50% 50%。

  接下來我們根據(jù)已知的圓角特性發(fā)揮想象構(gòu)建各種各樣的圖形。

  border-radius: 50% / 100% 100% 0 0(當(dāng)圓角半徑不滿4個(gè)時(shí),css會(huì)自動(dòng)幫你重復(fù))

  border-radius: 100% 0 0 100% / 50%;

  border-radius: 100% 0 0 0 / 100% 0 0 0;

糖果按鈕

當(dāng)實(shí)際應(yīng)用時(shí),充分利用圓角的特性加上一些想象,就可以構(gòu)造出可愛的糖果按鈕效果了。

.borderRadius{ 
            display: inline-block; 
            background: rgba(255,160,220,.8); 
            box-shadow: hsl(0, 0%, 60%) 0 3px 3px; 
            min-width: 200px; 
            height: 100px; 
            line-height: 200px; 
            border-radius: 50% 10% / 100% 10%; 
        }

.borderRadius{ 
            display: inline-block; 
            background: rgba(157, 255, 127, 0.8); 
            box-shadow: hsl(0, 0%, 60%) 0 3px 3px; 
            min-width: 160px; 
            height: 100px; 
            line-height: 200px; 
            border-radius: 20% 20% 12% 12%/ 80% 80% 12% 12%; 
        }

.borderRadius{ 
            display: inline-block; 
            background: rgba(167, 255, 250, 0.8); 
            box-shadow: hsl(0, 0%, 60%) 0 3px 3px; 
            min-width: 160px; 
            height: 100px; 
            line-height: 200px; 
            border-radius: 20% / 50%; 
        }

是不是挺可愛的,這樣就不用經(jīng)常勞煩美工同志做圖啦,
但是在應(yīng)用之前一定要確認(rèn)適用的游覽器支持圓角屬性。