Sass mixin 使用css border属性画三角形
2016-03-14 16:16
423 查看
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;
}
}
//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;
}
}
相关文章推荐
- dispaly:table布局
- 2016.3.14__CSS 盒模型_第四天
- css3中-moz、-ms、-webkit分别代表的意思
- css height:100%失效
- css: position 与 z-index 问题(2)
- css:position 与 z-index 问题(1)
- css3(border-radius) 边框圆角详解
- css文本换行
- css学习任务二:切图写代码
- 【2016年Esri开发者大会亮点解析】矢量切片大显威力,GitHub上提供样式编辑器
- CSS入门笔记 - 初识CSS
- CSS3属性之text-overflow:ellipsis详解
- CSS学习笔记
- CSS选择器
- 导航条navigationBar上中间标题title 文字的样式
- CSS选择器
- 导入外部css文件时link和@import的区别
- css和js引用的相对路径
- css3中webkit-box的用法
- HTML+CSS Day10实例