CSS – 我想要为文本实现圆角(反向)角落

huangapple go评论70阅读模式
英文:

CSS - I would like to implement round (inverse) corner for texts

问题

我经常看到带有圆角设计。但我还没有看到实际的版本。我想自己实现这个,但除了使用反向边框半径之前/之后,我对实现没有任何想法。

特别是对于标题,我对此很感兴趣,其中这会自动调整,而且两行标题也没有问题。就像按钮上看到的那样,只是希望有一个文本段落。

有人对此有什么方法吗?会很高兴得到帮助。

英文:

I often see the design with the rounded corners. But I haven't seen a live version yet. I would like to implement this myself but except before/after with inverse-border-radius I have no idea for the implementation.

Especially for headings I would be interested in this, where this adjusts automatically and 2 line headings are no problem. As seen with the button, just like to have a text paragraph.

Does anyone have an approach for this. Would be happy about help

CSS – 我想要为文本实现圆角(反向)角落

答案1

得分: 1

没有所谓的"负边框半径"。如果您知道将要使用的背景,可以使用一些before/after元素来遮罩它:

body{
    background: #aaa;
    padding: 60px;
}
.big{
    background: #fff;
    padding: 100px;
    border-radius: 10px;
    position: relative;
}
.small{
    position:absolute;
    top: 0;
    left: 0;
    padding: 20px;
    border-radius: 10px;
    background: #888;
    outline: 10px solid #aaa;
}
.small:before{
    content: "";
    position:absolute;
    top: 0;
    right: -20px;
    width: 20px;
    height: 10px;
    background: radial-gradient(circle at 100% 100%, transparent 10px, #aaa 10px);
}
.small:after{
    content: "";
    position:absolute;
    left: 0;
    bottom: -20px;
    width: 10px;
    height: 20px;
    background: radial-gradient(circle at 100% 100%, transparent 10px, #aaa 10px);
}
<div class="big">
    <div class="small">Cutted out</div>
    Main content with image
</div>
英文:

there is no such thing as "negative border radius". If you know what background you will be using, you can mask it with some before/after elements:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body{
background: #aaa;
padding: 60px;
}
.big{
background: #fff;
padding: 100px;
border-radius: 10px;
position: relative;
}
.small{
position:absolute;
top: 0;
left: 0;
padding: 20px;
border-radius: 10px;
background: #888;
outline: 10px solid #aaa;
}
.small:before{
content: &quot;&quot;;
position:absolute;
top: 0;
right: -20px;
width: 20px;
height: 10px;
background: radial-gradient(circle at 100% 100%, transparent 10px, #aaa 10px);
}
.small:after{
content: &quot;&quot;;
position:absolute;
left: 0;
bottom: -20px;
width: 10px;
height: 20px;
background: radial-gradient(circle at 100% 100%, transparent 10px, #aaa 10px);
}

<!-- language: lang-html -->

&lt;div class=&quot;big&quot;&gt;

&lt;div class=&quot;small&quot;&gt;Cutted out&lt;/div&gt;
Main content with image
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月22日 20:17:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定