2012-05-11 44 views
5

如何使外部边界半径曲线在外?外部边界半径CSS属性曲线

enter image description here

底侧边框半径要弯道外侧。如何用CSS3做到这一点?

+0

,无需额外的标记这将是不可能的,因为图形的部分是外箱子模型。 – Paul

回答

5

是的,你可以做到这一点,没有任何额外的标记。像这样写:

CSS

.active{ 
    border:1px solid red; 
    border-bottom:0; 
    width:80px; 
    height:40px; 
    margin:30px; 
    position:relative; 
    -moz-border-radius:5px 5px 0 0; 
    -webkit-border-radius:5px 5px 0 0; 
    border-radius: 5px 5px 0 0; 
} 
.active:after, 
.active:before{ 
    content:''; 
    width:40px; 
    height:30px; 
    border:1px solid red; 
    position:absolute; 
    bottom:-3px; 
    border-top:0; 
} 
.active:after{ 
    border-left:0; 
    -moz-border-radius:0 0 5px 0; 
    -webkit-border-radius:0 0 5px 0; 
    border-radius: 0 0 5px 0; 
    left:-41px; 
} 
.active:before{ 
    border-right:0; 
    -moz-border-radius:0 0 0 5px; 
    -webkit-border-radius:0 0 0 5px; 
    border-radius: 0 0 0 5px; 
    right:-41px; 
} 

HTML

<div class="active">hi</div> 

入住这http://jsfiddle.net/p6sGJ/

+0

你忘了添加“真正的”border-radius属性。我们不希望再有这种疯狂:http://remysharp.com/2012/02/09/vendor-prefixes-about-to-go-south/ – peirix

+0

这很好,但我举了一个例子,支持-webkit &mozilla浏览器:) – sandeep

+1

是的,但问题是有人可能会复制粘贴你的代码,这可能是第一个问题的开始。所以我只是对答案做了一个快速编辑,顺便提一下,这是一个很好的解决方案,所以我们可以尽量避免这种情况。 – peirix