2013-07-16 38 views
4

的相交部分的顏色嘿所有我喜歡以創建CSS圓圈,它看起來像enter image description hereCSS界需要改變界

和我創建使用類中的CSS邊界半徑風格的圓我通過ID separted顏色

我頂嘴看起來是圓 類

.works_section{ 
     margin-top: 80px; 
     .work_circles{ 
      float: left; 
      width: 201px; 
      height: 201px; 
      border-radius: 101px; 
      display: block; 
      position: relative; 
      img{ 
       display: block; 
       margin: 0 auto; 
       margin-top: 65px; 
      } 
      p{ 
       margin-top: 15px; 
       color: white; 
       text-align: center; 
       font-weight: bold; 
      } 
     } 

// ID的DAT分離的顏色

 #firstblu_circle{ 
      @extend .work_circles; 
      background-color:$blue; 
      z-index: 1; 

     } 
     #yello_circle{ 
      @extend .work_circles; 
      background-color:$pale_yello; 
      z-index: 2; 
      left: -21px; 
     } 
     #radiumgreen_circle{ 
      @extend .work_circles; 
      background-color:$green; 
      z-index: 1; 
      left: -42px; 
     } 
     #pink_circle{ 
      @extend .work_circles; 
      background-color:$pnk; 
      z-index: 2; 
      left: -63px; 
     } 
     #lastblu_circle{ 
      @extend .work_circles; 
      background-color:$del_blue; 
      z-index: 1; 
      margin-left: -82px; 
     } 

    } 

And circle is look like 

Circles

現在我需要在我所描述的圖像圓的交叉領域添加白色的問題earlier.is有任何可能的方式通過CSS來得到它?

myfiddle是

fiddle

+3

我想,如果有人關心我會發佈一個廣義版本你正在使用wron g工具。使用SVG這會很容易;爲什麼你試圖在CSS中破解它讓自己變得困難? – Spudley

+0

@Spudley哦,是啊!謝謝我試試..! –

+0

我已經發布了我的評論作爲答案,更詳細一點。 – Spudley

回答

3

簡單一點的版本:Fiddle

<div class='circle-holder'> 
    <div id='circle-1' class='circle'></div> 
    <div id='circle-2' class='circle'></div> 
    <div id='circle-3' class='circle'></div> 
    <div id='circle-4' class='circle'></div> 
    <div id='circle-5' class='circle'></div> 
</div> 

CSS:

.circle { 
    width: 201px; 
    height: 201px; 
    border-radius: 101px; 
    float: left; 
    position: relative; 
    overflow: hidden; 
    margin-right: -30px; 
} 

.circle + .circle::before { 
    content: ''; 
    position: absolute; 
    width: 100%; 
    height: 100%; 
    top: 0; 
    left: -170px; 
    background: #fff; 
    border-radius: 101px; 
} 
+0

這與@DonDay的解決方案非常相似 –

+0

是的,我甚至使用了相同的標記:),但我的目標是實現視覺效果,而不需要像'clip-path'這樣的奇特(現在)特性。我打算儘可能使用傳統的CSS(這裏CSS3的唯一部分是'border-radius')。此外,在這種情況下,我更喜歡使用浮動內嵌塊,因爲它們不需要[與它們之間的空間作戰](http://css-tricks.com/fighting-the-space-between-inline-block-elements/ )。但是,我從他的解決方案中學到了很多東西,並積極參與其中。 –

+0

以其他人的小提琴爲出發點是可以接受的做法。我用VIVEk的代碼作爲起點。我沒有看到問題。此外,這個答案是乾淨整潔的東西。 –

3

簡短的回答是什麼你問的不是 可能 在CSS建議。至少,不是以任何明智的方式(給予足夠的標記,我猜任何東西是可能的,但這不是你真正想要的)。

通過使用opacity可以稍微接近您的預期結果;使圓圈半透明,並且它將給重疊段提供來自兩種重疊顏色的混合顏色。但那不是你想要的。

爲了獲得超出使用CSS的任何內容將是非常困難的,說實話,可能不值得。現代瀏覽器內置了SVG等功能,可以創建豐富的圖形效果,因此根本沒有理由嘗試在CSS中完成這種功能。只需使用SVG,你就會好起來的。

+0

恩......看看其他答案......好吧,他們是黑客,但生活也是如此;) –

+2

我站好了。有可能的。也許不明智,但可能。 :)我仍然認爲CSS是一個錯誤的工具:問題是即使得到了他想要的東西,如果他然後決定他想稍微修改它,它總會是一場與語言對抗的戰鬥來獲得它遵守。我們已經有了SVG,它是爲這種事情而明確設計的;它確實很好,非常容易,而且操作簡單,所以爲什麼不使用它? (並且在所有具有'border-radius'的瀏覽器中都支持它,所以他甚至沒有這個藉口) – Spudley

+1

我完全同意;我仍然會從第一句中的「不可能在純CSS中」改爲「不推薦在純CSS中」......只是我的2(謙虛)美分 –

3

DEMO:http://jsfiddle.net/Rfnca/7/

HTML

<div id="main"> 
    <span class="works_section" id="upload_circle"> 


    </span> 
    <span class="works_section" id="team_circle"> 



    </span> 
    <span class="works_section" id="development_circle"> 

    </span> 
    <span class="works_section" id="testing_circle"> 


    </span> 

    </div> 

CSS

.works_section{ 
    float: left; 
    width: 100px; 
    height: 100px; 
    border-radius: 101px; 
    display: block; 
    position: relative; 
} 
#upload_circle { 
    background-color: #25aed2; 
    z-index: 0; 
} 
#team_circle { 
    background-color: white; 
    z-index: 1; 
    left: -21px; 
    background-image: -moz-radial-gradient(
     -37px 50%, /* the -37px left position varies by your "gap" */ 
     circle closest-corner, /* keep radius to half height */ 
     transparent 0, /* transparent at center */ 
     transparent 55px, /*transparent at edge of gap */ 
     #f1ce0d 56px, /* start circle "border" */ 
     #f1ce0d 57px /* end circle border and begin color of rest of background */ 
    ); 
} 
#development_circle { 
    background-color: #fff; 
    z-index: 1; 
    left: -42px; 
    background-image: -moz-radial-gradient(
     -37px 50%, /* the -37px left position varies by your "gap" */ 
     circle closest-corner, /* keep radius to half height */ 
     transparent 0, /* transparent at center */ 
     transparent 55px, /*transparent at edge of gap */ 
     #26e489 56px, /* start circle "border" */ 
     #26e489 57px /* end circle border and begin color of rest of background */ 
    ); 
} 
#testing_circle { 
    background-color: #fff; 
    z-index: 2; 
    left: -63px; 
    background-image: -moz-radial-gradient(
     -37px 50%, /* the -37px left position varies by your "gap" */ 
     circle closest-corner, /* keep radius to half height */ 
     transparent 0, /* transparent at center */ 
     transparent 55px, /*transparent at edge of gap */ 
     #EC1A5F 56px, /* start circle "border" */ 
     #EC1A5F 57px /* end circle border and begin color of rest of background */ 
    ); 

} 

Scotts他回答了這個問題:CSS 3 Shape: "Inverse Circle" or "Cut Out Circle"

我只是用他的代碼有一些修改。

我剛剛爲firefox添加了屬性。 您可以從scotts的答案中獲得其餘瀏覽器的屬性

3

以下是FF only版本。http://jsfiddle.net/z3VXw/

<div class='circle-holder'> 
    <div id='circle-1' class='circle'></div> 
    <div id='circle-2' class='circle'></div> 
    <div id='circle-3' class='circle'></div> 
    <div id='circle-4' class='circle'></div> 
    <div id='circle-5' class='circle'></div> 
</div> 

<svg id="svg-defs"> 
    <defs> 
     <clipPath id="clip-bite-left"> 
      <path d="M0,30 L0,0 L202,0 L202,202 L0,202 L0,170 
        A101,101 0 0,0 0,30 
      "/> 
     </clipPath> 
     <clipPath id="clip-bite-right"> 
      <path d="M202,30 L202,0 L0,0 L0,202 L202,202 L202,170 
        A101,101 0 0,1 202,30 
      "/> 
     </clipPath> 
     <clipPath id="clip-bite-both"> 
      <path d="M0,30 L0,0 L202,0 L202,30 
        A101,101 0 0,0 202,170 
        L202,202 L0,202 L0,170 
        A101,101 0 0,0 0,30 
      "/> 
     </clipPath> 
    </defs> 
</svg> 

CSS

.circle-holder { 
    width: 1200px; 
} 
.circle { 
    _float: left; 
    width: 201px; 
    height: 201px; 
    border-radius: 101px; 
    display: inline-block; 
    position: relative; 
} 

#circle-1 { 
    background-color:#25AED2; 
} 
#circle-2 { 
    background-color:#F1CE0D; 
    left: -30px; 
} 
#circle-3 { 
    background-color:#26E489; 
    left: -60px; 
} 
#circle-4 { 
    background-color:#EC1A5F; 
    left: -90px; 
} 
#circle-5 { 
    background-color:#25C8D2; 
    left: -120px; 
} 

#circle-1 { 
    clip-path: url(#clip-bite-right); 
} 
#circle-2, #circle-3, #circle-4 { 
    clip-path: url(#clip-bite-both); 
} 
#circle-5 { 
    clip-path: url(#clip-bite-left); 
} 
+0

由SVG修復的問題不適用於webkit的.. :( –