2016-09-09 42 views
3

請幫我我要讓一個div像這樣enter image description here如何在css中繪製內半徑?

+0

請告訴我們你有什麼到目前爲止已經試過。 –

+0

我試圖用邊界半徑,但是繪製其他方式。 – Shahid

+0

即使它不起作用,請向我們顯示您的代碼,我們會盡力幫助您解決您的問題。 –

回答

3

方法#01:

使用raidal-gradient

body { 
 
    background: #f0f0f0; 
 
    margin: 0; 
 
} 
 
.box { 
 
    background: radial-gradient(circle at bottom right, transparent 60px, #000 60px); 
 
    height: 150px; 
 
    width: 250px; 
 
}
<div class="box"></div>

方法#02:

您可以:before:after僞元素和box-shadow CSS屬性的組合來創建它。

body { 
 
    background: #f0f0f0; 
 
    margin: 0; 
 
} 
 
.box { 
 
    position: relative; 
 
    overflow: hidden; 
 
    height: 150px; 
 
    width: 250px; 
 
} 
 

 
.box:before { 
 
    box-shadow: 0 0 0 1000px #000; 
 
    border-radius: 100%; 
 
    position: absolute; 
 
    bottom: -30px; 
 
    height: 100px; 
 
    right: -35px; 
 
    width: 100px; 
 
    z-index: -1; 
 
    content: ''; 
 
}
<div class="box"></div>

3

的最簡單的方法將使用pseudo element。通過絕對定位:after元素,您可以獲得理想的效果。

.box { 
 
    background: #000; 
 
    width: 300px; 
 
    height: 150px; 
 
    position: relative; 
 
} 
 
.box:after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 150px; 
 
    height: 150px; 
 
    border-radius: 50%; 
 
    background: #fff; 
 
    right: -75px; 
 
    bottom: -75px; 
 
}
<div class="box"></div>

+0

但如果我不想在圓角的白色背景然後如何? – Shahid

+0

這是做得很好,但是當我在這個div內設置圖像時,它不會從這個邊緣切割。 – Shahid

2

試試這個CSS,

.rec{ 
    height: 200px; 
    background: black; 
    position: relative; 
    width:600px; 
} 

.rec:after { 
    content: ''; 
    position: absolute; 
    bottom: -20px; right: -20px; 
    border-bottom: 100px solid white; 
    border-left: 100px solid white; 
    width: 0; 
    background:#fff; 
    border-radius:150px; 

}