CSS 3形状:"反向圆"或"剪切圆"

Alp*_*Alp 40 css css3 css-shapes

我想创建一个形状,我将其描述为"反向圆":

CSS形状

图像在某种程度上是不准确的,因为黑线应该沿div元素的外边界继续.

这是我目前所拥有的演示:http://jsfiddle.net/n9fTF/

CSS没有图像,这甚至可能吗?

Sco*_*ttS 53

更新:CSS3径向背景渐变选项

(对于那些支持它的浏览器 - 在FF和Chrome中测试 - IE10,Safari也应该工作).

我原来答案的一个"问题"是那些没有坚实背景的情况.此更新产生相同的效果,允许圆与其反向剪切之间的透明"间隙".

见示例小提琴.

CSS

.inversePair {
    border: 1px solid black;
    display: inline-block;    
    position: relative;    
    height: 100px;
    text-align: center;
    line-height: 100px;
    vertical-align: middle;
}

#a {
    width: 100px;
    border-radius: 50px;
    background: grey;
    z-index: 1;
}

#b {
    width: 200px;
    /* need to play with margin/padding adjustment
       based on your desired "gap" */
    padding-left: 30px;
    margin-left: -30px;
    /* real borders */
    border-left: none;
    -webkit-border-top-right-radius: 20px;
    -webkit-border-bottom-right-radius: 20px;
    -moz-border-radius-topright: 20px;
    -moz-border-radius-bottomright: 20px;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
    /* the inverse circle "cut" */
    background-image: -moz-radial-gradient(
        -23px 50%, /* the -23px 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 */
        black 56px, /* start circle "border" */
        grey 57px /* end circle border and begin color of rest of background */
    );
    background-image: -webkit-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
    background-image: -ms-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
    background-image: -o-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
    background-image: radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
}
Run Code Online (Sandbox Code Playgroud)

原始答案

比我预期的更多的努力使z-indexing工作(这似乎忽略了负的z-index),但是,这给了一个漂亮干净的外观(在IE9,FF,Chrome中测试):

HTML

<div id="a" class="inversePair">A</div>
<div id="b" class="inversePair">B</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.inversePair {
    border: 1px solid black;
    background: grey;
    display: inline-block;    
    position: relative;    
    height: 100px;
    text-align: center;
    line-height: 100px;
    vertical-align: middle;
}

#a {
    width: 100px;
    border-radius: 50px;
}

#a:before {
    content:' ';
    left: -6px;
    top: -6px;
    position: absolute;
    z-index: -1;
    width: 112px; /* 5px gap */
    height: 112px;
    border-radius: 56px;
    background-color: white;
} 

#b {
    width: 200px;
    z-index: -2;
    padding-left: 50px;
    margin-left: -55px;
    overflow: hidden;
    -webkit-border-top-right-radius: 20px;
    -webkit-border-bottom-right-radius: 20px;
    -moz-border-radius-topright: 20px;
    -moz-border-radius-bottomright: 20px;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
}

#b:before {
    content:' ';
    left: -58px;
    top: -7px;
    position: absolute;
    width: 114px; /* 5px gap, 1px border */
    height: 114px;
    border-radius: 57px;
    background-color: black;
} 
Run Code Online (Sandbox Code Playgroud)


Chr*_*her 8

我无法从你的绘图中看出你想要点数的四舍五入,但这里有一种可能性:http: //jsfiddle.net/n9fTF/6/

如果点数需要更圆,你需要在末端放一些圆圈,以便它们与大铲子混合.


web*_*iki 5

不同的方法:盒子阴影

这种方法使用IE9 +支持的 CSS框阴影(canIuse)

DEMO

输出:

使用框阴影的嵌入曲线的CSS形状

HTML:

<div id="a">
    <div id="b"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

#a{
    overflow:hidden;
    border-radius:20px;
    position:relative;
    display:inline-block;
}
#a:before, #a:after{
    content:'';
    width: 100px;
    border-radius: 50%;
}
#a:before {
    height: 100px;
    float:left;    
    border: 1px solid black;
    background: grey;
}
#a:after {
    position:absolute;
    left:14px; top:-6px;
    height:114px;
    box-shadow: 1px 0px 0px 0px #000, 110px 0px 0px 68px #808080;
    background:none;
    z-index:-1;
}
#b {
    width: 200px;
    height: 100px;
    background:none;
    margin-left:-15px;
    border: 1px solid black;
    border-left:none;
    float:left;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
}
Run Code Online (Sandbox Code Playgroud)