border radius with css triangles

妖精的绣舞 提交于 2019-12-01 04:29:16

问题


I have a rectangle where each side of the diagonal has it's own color

div {
    width: 0;
    height: 0;    
    border-left: 150px solid green;
    border-top: 100px solid gray;
}

Now I wanted to add a border-radius to the div, but then I noticed that this works fine for all sides except for bottom left.

So if I add:

border-radius: 10px 10px 10px 0;

I get this:

.. but as soon as I add a bottom left border-radius, I get this:

1) Why does this happen?

2) Is there an easy fix?

Edit:

I'm using Chrome, but I just looked a firefox and IE and the results are different!

Firefox:

IE 11

What's going on?


回答1:


Try to add a wrapping container:

<div class="wrap">
    <div class="triangle"></div>
</div>

with this style:

.wrap {
    display: inline-block;
    overflow: hidden;
    border-radius: 10px;
}

overflow: hidden; should do the trick.

Demo: http://jsfiddle.net/dfsq/9xDVj/8/



来源:https://stackoverflow.com/questions/22296125/border-radius-with-css-triangles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!