Question

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

Was it helpful?

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

OTHER TIPS

you can get those borders too if you want (I have improved the previous answer by Olaf Dietsche):

HTML:

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

CSS:

li.breadcrumb:before {
    content:'';
    width: 28.28427px; /* sqrt(40*40 / 2) */
    height: 28.28427px;
    background:transparent;
    position:absolute;
    -moz-transform:rotate(45deg);
    -webkit-transform:rotate(45deg);
    transform:rotate(45deg);
    transform-origin: top right;
    top: 20px;
    margin:0;
    right: 0;
    border-right: #000 solid 1px;
    border-top: #000 solid 1px;
}

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;
    position: relative;
    height: 40px;
}
li.first-crumb {
    background: #aaa;
}
li.last-crumb {
    background: #eee;
}
li.breadcrumb a {
    text-decoration: none;
}

and the fiddle: http://jsfiddle.net/piotku/9cs1zy4h/

Another way to do it is to use an :after element and make this a rectangle with two borders and rotate this.

Here is an example: Breadcrumb

Main CSS:

li-item:after {
  content: "";
  width: 5rem;
  height: 100%;
  display: inline-block;
  position: absolute;
  background: transparent;
  right: 0;
  top: 0;
  transform: translateX(-1rem) rotate(45deg); 
  border-right: 4px solid white;
  border-top: 4px solid white;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top