Sass mixin 使用css border属性画三角形

To be finished.

 

//triangle
@mixin css-triangle ($direction: "down", $size: 20px, $color: #000, $fillColor:#fff) {
    width: 0;
    height: 0;
    position: relative;
    z-index: 0;
    border-left: #{setTriangleSize($direction, "left", $size)} solid #{setTriangleColor($direction, "left", $color)};
    border-right: #{setTriangleSize($direction, "right", $size)} solid #{setTriangleColor($direction, "right", $color)};
    border-bottom: #{setTriangleSize($direction, "bottom", $size)} solid #{setTriangleColor($direction, "bottom", $color)};
    border-top: #{setTriangleSize($direction, "top", $size)} solid #{setTriangleColor($direction, "top", $color)};

    .#{$namespace}triangle-fill{
        width: 0;
        height: 0;
        position: absolute;
        left: -($size/2-1);
        top:-($size);
        z-index: 1;
        border-left: #{setTriangleSize($direction, "left", $size)} solid #{setTriangleColor($direction, "left", $fillColor)};
        border-right: #{setTriangleSize($direction, "right", $size)} solid #{setTriangleColor($direction, "right", $fillColor)};
        border-bottom: #{setTriangleSize($direction, "bottom", $size)} solid #{setTriangleColor($direction, "bottom", $fillColor)};
        border-top: #{setTriangleSize($direction, "top", $size)} solid #{setTriangleColor($direction, "top", $fillColor)};
    }
}
@function setTriangleColor($direction, $side, $color) {

    @if $direction == "left" and $side == "right"
    or  $direction == "right" and $side == "left"
    or $direction == "down" and $side == "top"
    or $direction == "up" and $side == "bottom" {
        @return $color
    } @else {
        @return "transparent";
    }
}
@function setTriangleSize($direction, $side, $size){
    @if (($direction == "left" or $direction == "right") and ($side=="left" or $side=="right"))
        or (($direction == "up" or $direction == "down") and ($side=="top" or $side=="bottom")){
        @return $size/2;
    } @else{
        @return $size;
    }
}

@function setTriangleOffset($direction, $side, $size){
    @if (($direction == "left" or $direction == "right") and ($side=="left" or $side=="right"))
        or (($direction == "up" or $direction == "down") and ($side=="top" or $side=="bottom")){
        @return $size/2;
    } @else{
        @return $size;
    }
}

转载于:https://www.cnblogs.com/wsion/p/5276108.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值