css 使用CSS渐变的斜角和负边界半径

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 使用CSS渐变的斜角和负边界半径相关的知识,希望对你有一定的参考价值。

{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
// alert('Hello world!');
<div><p>The main idea is to have 4 gradients that each occupy a quarter of the element's area (one for the bottom left, one for the bottom, on of the top right and one for the top left). Then you set the background to 4 linear gradients with the same color stops (in this case we wanted the corner size to be 10px*, so it was transparent <strong>until</strong> 10px and then the color we want <strong>from</strong> 10px) except the corners that are 45deg, 135deg, 225deg and 315deg respectively.</p>
    <p><small>*Actually not exactly 10px, it's the length of the hypotenuse of an isosceles right-angled triangle, which is around 14px</small></p></div>

<div class="round">By using radial gradients, you can simulate rounded corners with a negative radius. Just in this case, don't put the color stops at the exact same position, since the result will be too aliased in most browsers (and kinda still is in Webkit).</div>
/**
 * Beveled corners & negative border-radius with CSS gradients
 */

div {    
	background: #c00; /* fallback */
	background:
		linear-gradient(135deg, transparent 10px, #c00 0) top left,
		linear-gradient(225deg, transparent 10px, #c00 0) top right,
		linear-gradient(315deg, transparent 10px, #c00 0) bottom right,
		linear-gradient(45deg,  transparent 10px, #c00 0) bottom left;
	background-size: 50% 50%;
	background-repeat: no-repeat;
}

div.round {
	background-image:
		radial-gradient(circle at 0 0, 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 100% 100%, rgba(204,0,0,0) 14px, #c00 15px),
		radial-gradient(circle at 0 100%, rgba(204,0,0,0) 14px, #c00 15px);
}

/* Ignore the CSS from this point, it's just to make the demo more presentable */
body {
    background: #444 url('http://lea.verou.me/ft2010/img/darker_wood.jpg') bottom;
    font-family: sans-serif;
}

div {
    width: 500px;
    margin:15px auto;
    padding:13px 15px;
    color: white;
    line-height:1.5;
}

p:first-of-type { margin-top: 0 }
p:last-of-type { margin-bottom: 0}

以上是关于css 使用CSS渐变的斜角和负边界半径的主要内容,如果未能解决你的问题,请参考以下文章

CSS3PIE 不使用边界半径 [重复]

CSS 带有CSS3边界半径的CSS圆角

CSS CSS3边界半径

CSS CSS - 边界半径

CSS 所有四个角的CSS3边界半径

在 IE9 中使用 CSS3 PIE 的线性渐变不起作用,IE8 可以