Drawing a triangle with rounded bottom in CSS?

人盡茶涼 提交于 2019-12-12 01:33:06

问题


In css I can draw a triangle as following:

.triangle{
    width: 0px;
    height: 0px;
    border-style: solid;
    border-width: 0 200px 200px 0;
    border-color: transparent #48a665 transparent transparent;
}

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

Jsfiddle

Now I want to draw a triangle with rounded at bottom like this:

Is it possible to make it with CSS?


回答1:


So we create a circle and place it on top to make it look like how you want it, you get something like this:

CSS:

.triangle{
    width: 0px;
    height: 0px;
    border-style: solid;
    border-width: 0 200px 200px 0;
    border-color: transparent #48a665 transparent transparent;
}
.triangle:after {
    content: "";
    display: block;
    width: 400px;
    height: 400px;
    background: #fff;
    border-radius: 200px;
    left: -190px;
    position: absolute;
}

You need to set the background color (currently #fff ) to match the background it is placed on.

DEMO HERE




回答2:


On the assumption of a solid background area for the concave section, you can use:

Demo Fiddle

CSS

div {
    background:red;
    height:200px;
    width:200px;
    position:relative;
    overflow:hidden;
}
div:after {
    position:absolute;
    content:'';
    display:block;
    height:200%;
    width:200%;
    left:-100%;
    background:white; /* <-- change as appropriate */
    border-radius:100%;
}

This simply overlays an offset circle onto the element, positioned to cover up a section of it to leave the appearance of the element being concave.



来源:https://stackoverflow.com/questions/23423516/drawing-a-triangle-with-rounded-bottom-in-css

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