CSS3创建圆角三角形元素

时间:2013-09-14 08:03:53

标签: html css css3 html-lists css-shapes

我只知道圆边的方式。无法弄清楚如何创建这种无图像ul li标签。 如你所见,它不完全是三角形:它的顶部和底部有点圆润。是否可以使用css3创建与下图最相似的内容?如果有,怎么样?

提前谢谢!

enter image description here

3 个答案:

答案 0 :(得分:8)

加价:

首先,您必须按照以下方式定义化妆:

<menu type=list>
    <li>home</li> 
    <li>work</li>  
</menu>

然后使用skew,rotate,box-shadow,border-radius和CSS Pseudo-elements,如下所示:

来源:http://www.w3schools.com/css3/css3_2dtransforms.asp         http://www.w3schools.com/cssref/css3_pr_box-shadow.asp         http://www.w3schools.com/cssref/css3_pr_border-radius.asp         http://www.w3schools.com/css/css_pseudo_elements.asp

演示1:http://jsfiddle.net/kougiland/mVu2z/5/ enter image description here

menu{
   position:relative;
   width:320px;
   height:40px;
}

li{
    float:left;
    width:50%;
    background-color:red;
    list-style:none;
    position:relative;
    height:54px;
    text-align:center;
    line-height:50px;
    color:white;
}

li:before,li:after{
    position: absolute;
    content: "";
    height: 32px;
    width: 32px;
    border-radius: 4px;
    background-color: red;
    top: 11px;
    -webkit-transform: rotate(45deg) skew(16deg,16deg);
    -moz-transform: rotate(45deg) skew(16deg,16deg);
    transform: rotate(45deg) skew(16deg,16deg);
}
li:before{
    left:-15px;
}
li:after{
    right:-15px;
}
li:nth-child(2):before{
    box-shadow: 0px 0 0 black,-4px 4px 0 black;
}

演示2:http://jsfiddle.net/kougiland/mVu2z/4/ enter image description here

风格:

menu{
   position:relative;
   width:320px;
   height:40px;
}

li{
    float:left;
    width:50%;
    background-color:red;
    list-style:none;
    position:relative;
    height:54px;
    text-align:center;
    line-height:50px;
    color:white;
}

li:before,li:after{
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    border-radius: 4px;
    background-color: red;
    top: 14px;
    -webkit-transform: rotate(45deg) skew(30deg,30deg);
    -moz-transform: rotate(45deg) skew(30deg,30deg);
    transform: rotate(45deg) skew(30deg,30deg);
}
li:before{
    left:-13px;
}
li:after{
    right:-13px;
}
li:nth-child(2):before{
    box-shadow: 0px 0 0 black,-4px 4px 0 black;
}

演示3:http://jsfiddle.net/kougiland/mVu2z/ enter image description here

menu{
   position:relative;
   width:320px;
   height:40px;
}

li{
    float:left;
    width:50%;
    background-color:red;
    list-style:none;
    position:relative;
    height:54px;
    text-align:center;
    line-height:50px;
    color:white;
}

li:before,li:after{
    position:absolute;
    content:"";
    height:40px;
    width:40px;
    border-radius:4px;
    background-color:red;
    top: 7px;
    -webkit-transform:rotate(45deg);
    -moz-transform:rotate(45deg);
    transform:rotate(45deg);
}
li:before{
    left:-20px;
}
li:after{
    right:-20px;
}
li:nth-child(2):before{
    box-shadow: 0px 0 0 black,-4px 4px 0 black;
}

答案 1 :(得分:2)

您可以将CSS transform rotate属性与border-radius一起使用,在这里,我旋转了一个:after伪,它位于容器元素的绝对位置。而不是使用border-radius作为曲线。

Demo

div {
    height: 30px;
    width: 100px;
    background: #f00;
    position: relative;
    margin: 100px;
}

div:after {
    background-color: #f00;
    content: "";
    display: block;
    height: 22px;
    width: 22px;
    transform: rotate(45deg);
    border-radius: 0 10px 0 0;
    right: -11px;
    top: 4px;
    position: absolute;
}

答案 2 :(得分:0)

当然! Chris Coyier写了一篇很酷的代码:

http://css-tricks.com/triangle-breadcrumbs

相关问题