Pointed/angled arrow-style borders in CSS

前端 未结 3 2098
我寻月下人不归
我寻月下人不归 2021-02-05 21:46

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

3条回答
  •  我在风中等你
    2021-02-05 22:14

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

    HTML:

    
    

    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/

提交回复
热议问题