sass处理公共样式问题

首先需要定义一个文件夹style
在这里插入图片描述
style中定义公共样式文件
style——
_minix.scss //这个文件放我们公共的样式方法和处理函数
main.sass //这个是我们每个样式文件中引入的文件,这个文件中@import ‘./mixin’;

//处理样式自适应问题  基于iPhone 6 375px的像素宽度
@function px2rem($x) {
    @return $x / 37.5 * 1rem;  //sass中使用$
    @return @x / 37.5 * 1rem;  //less中使用@
}

//没有参数   内容过长现实...
@mixin ellipsis {
	  text-overflow: ellipsis;
	  white-space: nowrap;
	  overflow: hidden;
}
	//使用方式
	.className{
		max-width:100px;
		height:30px;
		@include ellipsis();
	}

//带参数  浮动:默认值是left
@mixin float($float:left) { 
		float: $float;
		// 兼容性判断
	 	@if $lte7 {
	  		display: inline; 
	 	} 
}
	//使用方式
	.classNameLeft{
		@include float();
	}
	.classNameRight{
		@include float(right);
	}

// 带判断  三角形 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; 
	} 
}

猜你喜欢

转载自blog.csdn.net/qq_37815292/article/details/87808300
今日推荐