Pure CSS triangle with semi-transparent border. Possible?

前端 未结 2 788
时光说笑
时光说笑 2021-01-30 18:25

Is it possible to draw an arrow that has semi-transparent border around it just using css? \"enter

相关标签:
2条回答
  • 2021-01-30 18:51

    This still needs some work, but here's the general idea:

    Use a pseudo-element, rotate it 45deg and apply the styling to that:

    .arrow {
        bottom: -25px; 
        left: 30px; 
        width: 40px;
        height: 40px;
        position: absolute;
        overflow: hidden;
    }
    .arrow:after {
        content: ' ';
        display: block;
        background: red;
        width: 20px;
        height: 20px;
        transform: rotate(45deg);
        position: absolute;
        top: -19px;
        left: 3px;
        background: #999;
        border: 5px solid rgba(0, 0, 0, 0.2);
        background-clip: padding-box;
    }
    

    Here's the fiddle: http://jsfiddle.net/yZ3vB/


    The problem with this is that the borders overlap, making it darker by the edges.

    This could probably be remedied by adding another element though.

    Update: Yes! Here you go: http://jsfiddle.net/sJFTT/


    Update 2: You don't even need that additional element. You can use the pseudo element from the main box:

    .ui-overlay-content:after {
        content: ' ';
        border-width: 13px;
        border-color: #999 transparent transparent;
        border-style: solid;
        bottom: -10px;
        left: 30px;
        width: 0;
        height: 0;
        position: absolute;
    }
    

    Here's the fiddle: http://jsfiddle.net/6v9nV/


    Update 3: Actually, you can do all this with just a single element and no transform, by using both pseudo-elements - the before and the after:

    .speech-bubble {
        background: #999;
        background: linear-gradient(top, #444 0%,#999 100%);
        background-clip: padding-box;
        border: 5px solid rgba(0, 0, 0, 0.2);
        padding: 20px;
        width: 200px;
        height: 100px;
        position: relative;
    }
    .speech-bubble:before{
        content: ' ';
        border-color: rgba(0, 0, 0, 0.2) transparent transparent;
        border-style: solid;
        border-width: 17px;
        position: absolute;
        bottom: -39px;
        left: 16px;
    }
    .speech-bubble:after{
        content: ' ';
        border-color: #999 transparent transparent;
        border-style: solid;
        border-width: 13px;
        position: absolute;
        bottom: -26px;
        left: 20px;
    }
    

    Here's the fiddle: http://jsfiddle.net/95vvr/


    P.S. Don't forget the vendor prefixes in production!

    0 讨论(0)
  • 2021-01-30 19:03

    You need notch image and place that image absolutely at bottom right corner.enter image description here

    0 讨论(0)
提交回复
热议问题