微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CSS 3形状:“反向圆”或“剪切圆”

我想创建一个形状,我将其描述为“反转圆”:

图像有点不准确,因为黑线应该沿着div元素的外边界继续。

这里是我现在的一个演示:http://jsfiddle.net/n9fTF/

这是甚至可能与CSS没有图像?

解决方法

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

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

我的原始答案的一个“问题”是那些没有坚实的背景,他们正在反对的情况。此更新创建相同的效果,允许圆形和它的反切割之间的透明“间隙”。

See example fiddle

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) 55px,black 56px,grey 57px);
    background-image: -ms-radial-gradient(-23px 50%,grey 57px);
    background-image: -o-radial-gradient(-23px 50%,grey 57px);
    background-image: radial-gradient(-23px 50%,grey 57px);
}

原始答案

比我预期的z-indexing工作(this seems to ignore the negative z-index),但是,this gives a nice clean look(在IE9,FF,Chrome测试):

HTML

<div id="a" class="inversePair">A</div>
<div id="b" class="inversePair">B</div>

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;
}

原文地址:https://www.jb51.cc/css/221914.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。