Search code examples
htmlcssbordercss-shapes

Pointed/angled arrow-style borders in CSS


I'm making a breadcrumb menu and attempting to do it in pure CSS so I don't have to use a background image to get an arrow shape. Is it possible to achieve this angled border style with pure CSS?

Arrow breadcrumbs

The best I have been able to do looks like this (this is just a draft screenshot I made a while ago, so please disregard that it implies that breadcrumbs are fruits and/or delicious):

enter image description here

I was achieving it using CSS like this:

.breadcrumb li {
    border-right: 2px solid #ECECEC;
    border-top-right-radius: 40px;
    border-bottom-right-radius: 40px;
}

Here's the whole CSS in case it helps:

div.breadcrumb {
    display: block;
    float: left;
    border-bottom: 2px solid gray;
}
ul.breadcrumb {
    display: block;
    float: left;
    list-style-type: none;
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;
}
.breadcrumb li {
    float: left;
    display: list-item;
    background-color: #F2F2F2;
    border-right: 2px solid #ECECEC;
    border-top-right-radius: 40px;
    border-bottom-right-radius: 40px;
    position: relative;
    padding: 9px 20px 10px 35px;
    margin-left: -32px;
}
.breadcrumb li.first-crumb {
    background: #E7E7E7;
    padding-left: 20px;
    margin-left: 0px;
}
.breadcrumb li.last-crumb {
    border-top: 1px solid #E3E3E3;
    border-right: 1px solid #E3E3E3;
    background: white;
    padding-top: 9px;
    padding-bottom: 9px;
    border-top-right-radius: 0px;
    border-bottom-right-radius: 0px;
}
.breadcrumb li:not(.first-crumb) {
    padding-left: 45px;
}
.breadcrumb li:not(.last-crumb) a:after {
    content: "\27F6";
    margin-left: 10px;
    color: #444444;
    margin-right: 0px;
}
.breadcrumb li a,
.breadcrumb li span {
    display: block;
    float: left;
    position: relative;
}
.breadcrumb li a {
    text-decoration: none;
}
.breadcrumb li.first-crumb a {
    padding-left: 0px;
    margin-left: 0px;
}

My markup looks like this:

<div class="breadcrumb">
    <ul class="breadcrumb">
        <li class="breadcrumb first-crumb"><a href="#">Produce</a></li>
        <li class="breadcrumb"><a href="#">Fruits</a></li>
        <li class="breadcrumb last-crumb"><span>breadcrumb-ilicious!</span></li>
    </ul>
</div>

Edit: It would be nice if I could get it to look like there's an actual border too. This is my crude skitch of it:

enter image description here

(I tried adding several triangles per Olaf's suggestion and the only thing I couldn't get to work was correcting the obvious gap between two triangles without changing the angle of the triangle poking out to form the border.)

enter image description here


Solution

  • Stealing from CSS Tricks - CSS Triangle, you can do something like

    li.breadcrumb:after {
        content: "";
        display: inline-block;
        width: 0;
        height: 0;
        border-top: 20px solid #eee;
        border-bottom: 20px solid #eee;
        border-left: 20px solid #ccc;
    }
    

    li.breadcrumb:after {
        content: "";
        display: inline-block;
        width: 0;
        height: 0;
        border-top: 20px solid #eee;
        border-bottom: 20px solid #eee;
        border-left: 20px solid #ccc;
    }
    li.first-crumb:after {
        border-top: 20px solid #ccc;
        border-bottom: 20px solid #ccc;
        border-left: 20px solid #aaa;
    }
    li.last-crumb:after {
        border-top: 20px solid #fff;
        border-bottom: 20px solid #fff;
        border-left: 20px solid #eee;
    }
    
    li.breadcrumb {
        list-style-type: none;
        background-color: #ccc;
        display: inline-block;
        float: left;
        line-height: 0;
    }
    li.first-crumb {
        background: #aaa;
    }
    li.last-crumb {
        background: #eee;
    }
    li.breadcrumb a {
        text-decoration: none;
    }
    <div class="breadcrumb">
        <ul class="breadcrumb">
            <li class="breadcrumb first-crumb"><a href="#">Hurr</a>
            </li>
            <li class="breadcrumb"><a href="#">Durr</a>
            </li>
            <li class="breadcrumb last-crumb"><span>Furr</span>
            </li>
        </ul>
    </div>
    <div class="arrow-right"></div>


    Original JSFiddle