博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用sass绘制三角形
阅读量:6885 次
发布时间:2019-06-27

本文共 1770 字,大约阅读时间需要 5 分钟。

hot3.png

用border生成三角形的@mixin:

// triangle@mixin triangle($direction, $size, $borderColor ) {  content:"";  height: 0;  width: 0;  @if $direction == top {    border-bottom:$size solid $borderColor;    border-left:$size dashed transparent;    border-right:$size dashed transparent;  }   @else if $direction == right {    border-left:$size solid $borderColor;    border-top:$size dashed transparent;    border-bottom:$size dashed transparent;  }   @else if $direction == bottom {    border-top:$size solid $borderColor;    border-left:$size dashed transparent;    border-right:$size dashed transparent;  }   @else if $direction == left {    border-right:$size solid $borderColor;    border-top:$size dashed transparent;    border-bottom:$size dashed transparent;  }}

这个@mixin主要有三个变量:第一个是方向的,因为三角形根据箭头朝向有四种方向,我们对应常用的css属性top,right,bottom,left;第二个表示三角形的大小;第三个表示颜色。当然你可以挑你常用的那个设置为变量的默认值,那样调用常用的那个就比较简单了,直接 triangle;就ok了。

编译之后的css代码:

/* line 192, ../sass/test1.scss */.top {  content: "";  height: 0;  width: 0;  border-bottom: 20px solid #322222;  border-left: 20px dashed transparent;  border-right: 20px dashed transparent;}/* line 195, ../sass/test1.scss */.bottom {  content: "";  height: 0;  width: 0;  border-top: 20px solid #322222;  border-left: 20px dashed transparent;  border-right: 20px dashed transparent;}/* line 198, ../sass/test1.scss */.left {  content: "";  height: 0;  width: 0;  border-right: 20px solid #322222;  border-top: 20px dashed transparent;  border-bottom: 20px dashed transparent;}/* line 201, ../sass/test1.scss */.right {  content: "";  height: 0;  width: 0;  border-left: 20px solid #322222;  border-top: 20px dashed transparent;  border-bottom: 20px dashed transparent;}

页面html代码:

效果:

转载于:https://my.oschina.net/liuyuantao/blog/801756

你可能感兴趣的文章
java实现简单的控制台管理系统
查看>>
建造模式
查看>>
Java 多线程(四)——线程同步(synchronized、ReentrantLock)
查看>>
遇到Could not load file or assembly ... or one of its dependencies怎么办
查看>>
TCP 上传文件
查看>>
Linux 重定向符:> ,>>, <
查看>>
金融行业注册电子邮箱账号时最需要注意什么?
查看>>
Xhprof安装
查看>>
所谓的linux集群-其实可以so easy
查看>>
关于OOM-killer
查看>>
Wireshark网络抓包(一)——数据包、着色规则和提示
查看>>
GOP/ 码流 /码率 / 比特率 / 帧速率 / 分辨率
查看>>
学习一门编程语言的各种矛盾
查看>>
sqlmap简单使用笔记
查看>>
Eclipse ME 安装详解(Windows XP)
查看>>
IE8及以下不支持trim()的处理方法
查看>>
Alpha 冲刺 (5/10)
查看>>
类的静态字段和构造函数
查看>>
TLE之前,没有一个节点叫失败!!!
查看>>
机器学习入门之二:一个故事说明什么是机器学习(转载)
查看>>