CSS: How to round box corners inside? [duplicate]

血红的双手。 提交于 2019-12-30 10:34:09

问题


There're border-radius property to round box corners. But how to round corners inside block, like subtracting circle?

Like here: http://malsup.com/jquery/corner/

Curl settings


回答1:


This can be done by adding four circular "gradient" background images on top of the normal background image, each positioned at the appropriate corner. There's an example on Lea Verou's blog. From that I've extracted a JSFiddle; the key code is

.round {
    background:
        radial-gradient(circle at 0 100%, rgba(204,0,0,0) 14px, #c00 15px),
        radial-gradient(circle at 100% 100%, rgba(204,0,0,0) 14px, #c00 15px),
        radial-gradient(circle at 100% 0, rgba(204,0,0,0) 14px, #c00 15px),
        radial-gradient(circle at 0 0, rgba(204,0,0,0) 14px, #c00 15px);

    background-position: bottom left, bottom right, top right, top left;
    background-size: 50% 50%;
    background-repeat: no-repeat;

    padding: 14px;
}



回答2:


No, there isn't a way to do it with pure CSS as far as I know. It's not even simple to do it with JavaScript or jQuery.

As far as I know, the jQuery plugin you linked is the one that works best for you, especially since you want a cross-browser solution, which advanced CSS3 isn't there yet, and it is the one you should use.




回答3:


There is one way to do it with pure CSS:

CSS code:

div {
height: 200px;
background: red;
position: relative;
width:200px;
}

div:after {
content: '';
position: absolute;
top: -20px; right: -20px;
border-top: 50px solid white;
border-left: 50px solid white;
width: 0;
background:#fff;
    border-radius:100px;

}
div:before {
content: '';
position: absolute;
top: -20px; left: -20px;
border-top: 50px solid white;
border-left: 50px solid white;
width: 0;
background:#fff;
    border-radius:100px;

}

HTML: <div></div>

Here is an example:



来源:https://stackoverflow.com/questions/18518179/css-how-to-round-box-corners-inside

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