选项卡与CSS的三角形边界

时间:2014-05-30 13:03:41

标签: css css3 border css-shapes

Tab border CSS3

我正试图在图片上表示我的HTML / CSS标签。

我已经用border-radius尝试过很多东西而没有任何成功。 你有任何曲目,以便我可以像CSS一样重现我的标签吗?

5 个答案:

答案 0 :(得分:4)

为了在图像中创建相同的边框(也在三角形内),您可以使用伪元素并变换旋转:

<强> DEMO

输出:

enter image description here

HTML:

<div>Critiques</div>
<div>Messages sur le forum</div>
<div>Actualités</div>

CSS:

div{
    border-top:1px solid #ccc;
    border-bottom:1px solid #ccc;
    padding-right:12px;
    line-height:50px;
    float:left;
    width:200px;
    position:relative;
    z-index:0;
    text-align:center;
}

div:after,div:before{
    content:'';
    position:absolute;
    width:10px;
    height:10px;
    background:#fff;
    z-index:999;

    -ms-transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}

div:before{
    border-right:1px solid #ccc;
    border-bottom:1px solid #ccc;
    top:0; left:-12px;

     -ms-transform-origin:100% 0;
    -webkit-transform-origin:100% 0;
    transform-origin:100% 0;
}

div:after{
    border-left:1px solid #ccc;
    border-top:1px solid #ccc;
    bottom:0;
    right:4px;

     -ms-transform-origin:0 100%;
    -webkit-transform-origin:0 100%;
    transform-origin:0 100%;
}
div:first-child:before, div:last-child:after{
    display:none;
}

答案 1 :(得分:3)

你可以用css但只有空跨度(如果你想在边缘有半个三角形):

HTML

<ul>
    <li><span></span>one</li>
    <li><span></span>two</li>
    <li><span></span>three</li>
</ul>

CSS

    ul {
        font-size: 0;
    }

    li {
        background: red;
        display: inline-block;
        padding: 30px;
        font-size: 15px;
        position: relative;
    }

    span {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }

    li:after {
        width: 0;
        height: 0;
        border-top: 10px solid white;
        border-left: 10px solid transparent;
        position: absolute;
        right: 0;
        top: 0;
        content: "";
    }

    li:before {
        width: 0;
        height: 0;
        border-top: 10px solid white;
        border-right: 10px solid transparent;
        position: absolute;
        left: 0;
        top: 0;
        content: "";
    }

    span:before {
        width: 0;
        height: 0;
        border-bottom: 10px solid white;
        border-right: 10px solid transparent;
        position: absolute;
        left: 0;
        bottom: 0;
        content: "";
    }

    span:after {
        width: 0;
        height: 0;
        border-bottom: 10px solid white;
        border-left: 10px solid transparent;
        position: absolute;
        right: 0;
        bottom: 0;
        content: "";
    }

示例:http://jsfiddle.net/fC9Fs/

答案 2 :(得分:1)

您可以使用八边形形状执行此操作,如this link

所示

相关代码:

#octagon { width: 100px; height: 100px; background: red; position: relative; } 
#octagon:before { content: ""; position: absolute; top: 0; left: 0; border-bottom: 29px solid red; border-left: 29px solid #eee; border-right: 29px solid #eee; width: 42px; height: 0; } #octagon:after { content: ""; position: absolute; bottom: 0; left: 0; border-top: 29px solid red; border-left: 29px solid #eee; border-right: 29px solid #eee; width: 42px; height: 0; }

您可以从上面的代码编辑边框,以获得您想要的确切形状。

答案 3 :(得分:1)

以下是另一种观点:

这个使用基本列表,不需要其他HTML。

同样如图中所示,第一个和最后一个元素没有箭头。

<强> Fiddle

HTML:

<ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
</ul>

CSS:

html, body{
    background:#E5E2E2;
}

ul{
    display:inline-block;
    list-style-type:none;
    border:1px solid #CCCCCC;
    padding:0;
}

li{
    float:left;
    padding:10px 15px;
    background:#F4F4F4;
    position:relative;
}

li:nth-child(n+2):before{
    content:'';
    position:absolute;
    left:-5px;
    top:-1px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 10px solid #e5e2e2;
}

li:nth-child(n+2):after{
    content:'';
    position:absolute;
    left:-5px;
    bottom:-1px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid #e5e2e2;
}

答案 4 :(得分:0)

我附带了另一个伪选项,允许偷工减料并允许查看背后的主要背景: DEMO

transparent cut off corners


也可以使用边框: DEMO with borders


该方法是在基本box-shadow三角形无法实现的旋转伪元素上从border绘制背景颜色。 伪元素几乎可以从半径和变换中获取任何形状 ...如果这给出了一些想法:)