Search code examples
cssgeometrybreadcrumbs

Triangle-style breadcrumbs without images


I created arrow(triangle)-style breadcrumbs with CSS, no images.

jsFiddle

html:

<ul class="breadcrumb">
    <li>Home</li>
    <li>First item</li>
    <li>Second item</li>
    <li>Last item</li>
</ul>

css:

.breadcrumb {
    list-style: none;
    overflow: hidden;
}
.breadcrumb li {
    background: #F6F6F6;
    padding: 5px 0 5px 36px;
    background: #F6F6F6;
    position: relative;
    display: block;
    float: left;
}
.breadcrumb li:before {
    content:" ";
    display: block;
    width: 0;
    height: 0;
    border-top: 25px solid transparent;
    border-bottom: 25px solid transparent;
    border-left: 20px solid #DDDDDD;
    position: absolute;
    top: 50%;
    margin-top: -25px;
    margin-left: 1px;
    left: 100%;
    z-index: 1;
}
.breadcrumb li:after {
    content:" ";
    display: block;
    width: 0;
    height: 0;
    border-top: 25px solid transparent;
    border-bottom: 25px solid transparent;
    border-left: 20px solid #F6F6F6;
    position: absolute;
    top: 50%;
    margin-top: -25px;
    left: 100%;
    z-index: 2;
}

The problem is when parent's width is not enough to display breadcrumbs in 1 line and it takes 2 lines (or more), overflow:hidden stops working and unwanted parts of triangles get visible (http://screencloud.net/v/fQEq).

Is there a way to fix that?


Solution

  • Try with this style:

    .breadcrumb {
        list-style: none;
        overflow: hidden;
    }
    .breadcrumb li:before {
        border-bottom: 15px solid transparent;
        border-left: 20px solid #dddddd;
        border-top: 15px solid transparent;
        content:" ";
        display: block;
        height: 0;
        left: 100%;
        margin-left: 1px;
        margin-top: -15px;
        position: absolute;
        top: 50%;
        width: 0;
        z-index: 1;
    }
    .breadcrumb li:after {
        border-bottom: 15px solid transparent;
        border-left: 20px solid #f6f6f6;
        border-top: 15px solid transparent;
        content:" ";
        display: block;
        height: 0;
        left: 100%;
        margin-top: -15px;
        position: absolute;
        top: 50%;
        width: 0;
        z-index: 2;
    }
    .breadcrumb li {
        background: none repeat scroll 0 0 #f6f6f6;
        display: block;
        float: left;
        height: 20px;
        padding: 5px 0 5px 33px;
        position: relative;
    }
    

    Hope it helps!