Search code examples
cssbordercss-shapes

Tabs border with triangle with CSS


Tab border CSS3

I am trying to represent my HTML/CSS tab like on the picture.

I have already tried lots of things with border-radius without any success. Do you have any tracks so that I can reproduce my tabs like the picture only with CSS?


Solution

  • In order to make the same borders (also inside the triangles) as in the image, you can use pseudo elements and transform rotate :

    DEMO

    output :

    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;
    }