2013-12-17 36 views
5

如何在CSS3中製作以下形狀,而不使用像「:before」這樣的僞類?CSS3 Moon Eclipse shape

Eclipse shape

我做到了,很容易:前,但事情是,我不希望有灰色區域的固體元件(見的jsfiddle - http://jsfiddle.net/aUdLr/2/

div{ 
    width: 100px; 
    height: 100px; 
    background-color: red; 
    border-radius: 100%; 
    position: relative; 
} 
div:before{ 
    content: ""; 
    width: 100%; 
    height: 110%; 
    background: gray; 
    position: absolute; 
    left: 5px; 
    top: -5%; 
    border-radius: 100%; 
} 
+0

[本網站](http://css-tricks.com/examples/ShapesOfCSS/)可能會對您有所幫助。儘管你的形狀沒有例子。 – AfromanJ

+0

這可能也有幫助:[靈活的谷歌樣式加載器與CSS](http://lea.verou.me/2013/11/flexible-google-style-loader-with-css/) – Kobi

回答

5

您可以使用邊框寬度:

div{ 
    width: 100px; 
    height: 100px; 
    border-radius: 100%; 
    border-width: 0; 
    border-left:solid 10px red; 
} 

科學準確例如:http://jsfiddle.net/aUdLr/4/

請記住,外形是而不是是一個完美的圓形,因爲邊框被添加到寬度。您可以通過減小寬度來補償,或者使用Box-sizing: Border-box

是我腦海
+1

n1,扔在' transform:scaleX(0.8)',你在那裏 – Kos

+0

謝謝你,你的解決方案是相關的。但是,我希望形狀與圖片完全一樣。我嘗試了其他方法,但仍然不是我需要的:http://jsfiddle.net/aUdLr/5/ –

1

最簡單的解決方案CSS3:

div:before { 
    font: 80px serif; 
    color: red; 
    content: "("; 
} 

Here's a fiddle.

(現在seriously-如果你想在板形控制量好,我建議使用SVG)。

2

要獲得較大圓圈黯然失色的小圓圈的效果,您可以爲透明元素添加陰影:

div{ 
    width: 100px; 
    height: 100px; 
    border-radius: 100%; 
    background-color:transparent; 
    box-shadow: -23px 0 0px -15px #ff8; 
} 

示例:http://jsfiddle.net/aUdLr/6/

+0

帶有多個陰影的示例:http://jsfiddle.net/aUdLr/7,http:// jsfiddle .net/aUdLr/8。這很有趣。 – Kobi

+0

另一種選擇是使用陰影'inset':http://jsfiddle.net/aUdLr/9/。我很肯定你可以通過稍微玩一些數字來得到你所需要的。 – Kobi