純 css3 指標箭頭與輪廓邊框

! 容器應相對或絕對定位

$direction - 頂部,底部,左側,右側

$margin - $direction 邊緣的邊距。對於頂部和底部方向 - 它是從左到右。對於左和右 - 它是從上到下。

$colors - 第一個是邊框顏色,第二個 - 是背景顏色(也許最好從父級繼承背景顏色)

$arrowSide - 是箭頭的相對大小

$isInset - 箭頭在其內部(true)或在其容器外部

這是一個有效的 Plunker https://plnkr.co/edit/PRF9eLwmOg8OcUoGb22Y?p=preview

%pointer-core {
    content: " ";
    position: absolute;
    border: solid transparent;
    z-index: 9999;
}

@mixin pointer($direction, $margin: 10px, $colors: (#999, $gray), $arrowSide: 8px, $isInset: false){

    $opposites: (
        top: bottom,
        bottom: top,
        left: right,
        right: left
    );

    $margin-direction: (
        top: left,
        bottom: left,
        left: top,
        right: top
    );

    &:before {
        @extend %pointer-core;
        border-width: $arrowSide;

        @if $isInset {
            border-#{$direction}-color: nth($colors, 1);
            #{$direction}: -1px;
        }
        @else
        {
            border-#{map-get($opposites, $direction)}-color: nth($colors, 1);
            #{map-get($opposites, $direction)}: 100%;
        }

        #{map-get($margin-direction, $direction)}: 0;

        margin-#{map-get($margin-direction, $direction)}: $margin - 1;
    }

    &:after {
        @extend %pointer-core;
        border-width: $arrowSide - 1;

        @if $isInset {
            border-#{$direction}-color: nth($colors, 2);
            #{$direction}: -1px;
        }
        @else
        {
            border-#{map-get($opposites, $direction)}-color: nth($colors, 2);
            #{map-get($opposites, $direction)}: 100%;
        }

        #{map-get($margin-direction, $direction)}: 0;

        margin-#{map-get($margin-direction, $direction)}: $margin;
    }
}