CSS3 倒圆角

发布于 2024-09-03 07:12:35 字数 373 浏览 2 评论 0原文

有没有办法在 CSS3 中做一个倒圆角,类似于下面(粗略)图中的左下角?

/-------\
|       |
|       |
|       |
| ______/
|/ <---The left side is flush (straight), the slant should be rounded

也许 border-radius 可以与这种技术结合使用?

编辑:我不是在寻找语音气泡,而是在寻找一种使左下角点的右侧弯曲的方法。

Is there a way to do an inverted rounded corner in CSS3, something approximately like the bottom left corner in the (crude) drawing below?

/-------\
|       |
|       |
|       |
| ______/
|/ <---The left side is flush (straight), the slant should be rounded

Perhaps border-radius could be combined with this technique?

Edit: I'm not looking for a speech bubble, but rather just a way to curve the right side of the point on the bottom left.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最初的梦 2024-09-10 07:12:35

好吧,这纯粹是疯狂,但肯定有办法实现这一点:-) 不是跨浏览器,但让我们看看:

我们的标记:

<div id="bubble">
    <p>This is madness!</p>
</div>

我们的 CSS:

#bubble {
    width:200px;
    height:100px;
    border:1px solid #000;
    -webkit-border-radius:20px;
    -moz-border-radius:20px;
    border-radius:20px;
}
    #bubble p {
        margin: 1em;
        font-family:Comic Sans MS;/* well, madness it is! */
    }
#bubble:before {
    content:'';
    border:20px solid;
    border-color:#fff transparent transparent;
    position:absolute;
    top:110px;
    left:25px;
    z-index:2;
}
#bubble:after {
    content:'';
    border:20px solid;
    border-color:#000 transparent transparent;
    position:absolute;
    top:111px;
    left:25px;
    z-index:1;
}

结果:
http://jsfiddle.net/MrLWY/

我只在 Firefox 3.6.3 中测试过这个,但是这个想法很清楚:-)

这里有两个:

#bubble {
    width:200px;
    height:100px;
    border:1px solid #000;
    position:relative;
    -webkit-border-radius:20px 20px 20px 0;
    -moz-border-radius:20px 20px 20px 0;
    border-radius:20px 20px 20px 0;
}
    #bubble p {
        margin: 1em;
        font-family:Comic Sans MS;
    }
#bubble:before {
    content:'';
    width:20px;
    height:20px;
    background:#fff;
    border-left:1px solid #000;
    position:absolute;
    top:100px;
    left:-1px;
}
#bubble:after {
    content:'';
    -webkit-border-radius:20px 0 0 0;
    -moz-border-radius:20px 0 0 0;
    border-radius:20px 0 0 0;
    border:solid #000;
    border-width:1px 0 0 1px;
    width:20px;
    height:19px;
    position:absolute;
    top:100px;
    left:0;
}

结果: http://jsfiddle.net/ajeN7/

也许这可以通过多种方式增强:

  • 让它跨浏览器(至少+webkit和opera)
  • 它可以在IE中工作,无需舍入,不过,在类似的帮助下 http://code.google.com/p/ie7-js/(为了使生成的内容正常工作)。
  • 了解它如何在灵活的高度下工作。
  • 更改字体系列声明:-)

Well, this is pure madness, but certainly there are ways to achieve this :-) not cross-browserly, but let's see:

Our mark-up:

<div id="bubble">
    <p>This is madness!</p>
</div>

Our CSS:

#bubble {
    width:200px;
    height:100px;
    border:1px solid #000;
    -webkit-border-radius:20px;
    -moz-border-radius:20px;
    border-radius:20px;
}
    #bubble p {
        margin: 1em;
        font-family:Comic Sans MS;/* well, madness it is! */
    }
#bubble:before {
    content:'';
    border:20px solid;
    border-color:#fff transparent transparent;
    position:absolute;
    top:110px;
    left:25px;
    z-index:2;
}
#bubble:after {
    content:'';
    border:20px solid;
    border-color:#000 transparent transparent;
    position:absolute;
    top:111px;
    left:25px;
    z-index:1;
}

The result:
http://jsfiddle.net/MrLWY/

I have only tested this in Firefox 3.6.3, but the idea is clear :-)

Here is take two:

#bubble {
    width:200px;
    height:100px;
    border:1px solid #000;
    position:relative;
    -webkit-border-radius:20px 20px 20px 0;
    -moz-border-radius:20px 20px 20px 0;
    border-radius:20px 20px 20px 0;
}
    #bubble p {
        margin: 1em;
        font-family:Comic Sans MS;
    }
#bubble:before {
    content:'';
    width:20px;
    height:20px;
    background:#fff;
    border-left:1px solid #000;
    position:absolute;
    top:100px;
    left:-1px;
}
#bubble:after {
    content:'';
    -webkit-border-radius:20px 0 0 0;
    -moz-border-radius:20px 0 0 0;
    border-radius:20px 0 0 0;
    border:solid #000;
    border-width:1px 0 0 1px;
    width:20px;
    height:19px;
    position:absolute;
    top:100px;
    left:0;
}

And the result: http://jsfiddle.net/ajeN7/

Perhaps this can be enhanced in many ways:

  • make it cross-browser (+webkit and opera, at least)
  • it could work in IEs, without roundings, though, with help of something like that http://code.google.com/p/ie7-js/ (in order for generated content to work).
  • to find out how it could work with flexible height.
  • to change the font-family declaration :-)
去了角落 2024-09-10 07:12:35

我还不能发表评论,但是这里有一个新的答案(关于 Gryzzlys 的答案):

Gryzzlys 的第一个示例没有处理不同的背景颜色(对于背景和气泡)。

但第二个却是这样。这是应用背景颜色的示例:

http://jsfiddle.net/tGnfb/

(我还添加了边框 - radius 属性,以便为 Firefox 以外的其他浏览器渲染边框)。

I cant comment yet, but so here's a new answer (in regard to Gryzzlys answer):

Gryzzlys first example didn't handle different background colors (for the background and bubble).

But the second one does. Here's an example with background colors applied:

http://jsfiddle.net/tGnfb/

(I also added border-radius properties so that it will render borders for other browsers than Firefox).

久而酒知 2024-09-10 07:12:35

这样就达到了FF中的效果。对其他浏览器使用适当的 border-radius 变体。
本质上,您使用 3 div 系统,其中一个系统的背景颜色相同。
仅适用于单色背景。

<div class="top">some text here</div>
<div class="bottom"><div class="bottom2"></div></div>

还有CSS:

body
    {
    background-color:red;
    }

.top
    {
    display: block;
    width: 200px;
    height: 50px;
    background-color:white;
    padding:5px;

    -moz-border-radius-topleft:10px;
    -moz-border-radius-topright:10px;
    -moz-border-radius-bottomright:10px;
    }

.bottom
    {
    display: block;
    width: 20px;
    height: 20px;
    background-color: white;    
    }

.bottom2
    {
    display: block;
    width: 20px;
    height: 20px;
    background-color: red;  
    -moz-border-radius-topleft:20px;
    }

This achieves the effect in FF. Use the appropriate border-radius variants for the other browsers.
Essentially you use a 3 div system, one with the same color of the background.
Does only work for background with a flat color.

<div class="top">some text here</div>
<div class="bottom"><div class="bottom2"></div></div>

And the CSS:

body
    {
    background-color:red;
    }

.top
    {
    display: block;
    width: 200px;
    height: 50px;
    background-color:white;
    padding:5px;

    -moz-border-radius-topleft:10px;
    -moz-border-radius-topright:10px;
    -moz-border-radius-bottomright:10px;
    }

.bottom
    {
    display: block;
    width: 20px;
    height: 20px;
    background-color: white;    
    }

.bottom2
    {
    display: block;
    width: 20px;
    height: 20px;
    background-color: red;  
    -moz-border-radius-topleft:20px;
    }
那片花海 2024-09-10 07:12:35

如果您想实现那种外观(语音气球),最好只使用图像:)

if you're trying to achieve that kind of look(a speech balloon) it's best to just use an image for that :)

深爱成瘾 2024-09-10 07:12:35

有多种方法可以仅使用 CSS 来解决此问题。我决定使用一种用于选项卡的技术 - 但可以很容易地适应语音气泡。

我在这里介绍了如何在 CSS 中制作 Inverse Border Radius 的基本示例(此处)。这使用了边框大小的技巧来使用内部,您可能需要进行一些定位才能使其正常工作,但是正如您所看到的,这是可能的。

There are ways you could solve this issue by using just CSS. I have decided to use a technique for tabs - but could be easily adapted for speech bubbles.

I cover a basic example here of how to make an Inverse Border Radius in CSS (here). This uses a trick with the size of Border to use the inside, you might have to do some positioning to get it to work properly however as you can see its possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文