gpt4 book ai didi

CSS 3 形状 : "Inverse Circle" or "Cut Out Circle"

转载 作者:数据小太阳 更新时间:2023-10-29 09:12:48 34 4
gpt4 key购买 nike

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

CSS Shape

图片有点不准确,因为黑线应该沿着 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) 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);
}

原始答案

为了让 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;
}

关于CSS 3 形状 : "Inverse Circle" or "Cut Out Circle",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10501488/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com