sass 基础

  1. scss 文件
.header {
	span {
		color: red;
		&:active {
			color: green;
		}
		&:hover {
			color: blue;
		}
	}
}
  1. sass 文件
.header
	span
		color: red
		&:active
			color: green
		&:hover
			color: blue

sass 中使用变量,运算,函数

$small-font: 14px + 3px;
$text-color: #555;
$default-font: 'microsoft yahei';

.title {
	color: lighten($text-color, 20%);
	font-family: $default-font;
}
.subtitle {
	color: darken($text-color, 20%);
	font-size: $small-font;
}
.text {
	color: $text-color;
	font-size: $small-font;
}

sass 的引入

/* main.scss */
@import 'viriables';
@import 'header';
@import 'content';

/* viriable.scss */
$color: red;
$content-color: orange;
$font-size: 12px;

/* header.scss */
.header {
	color: $color;
}
/* content.scss */
.content {
	color: $content-color;
}

mixin 用法

/* _mixin.scss */
@mixin singleline-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* main.scss */
@import 'mixin';
.text {
  width: 600px;
  @include singleline-ellipsis;
}
.content-text {
  width: 1000px;
  @include singleline-ellipsis;
}
  • 带参数
/* _mixin.scss */
@mixin singleline-ellipsis($width) {
  width: $width;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* main.scss */
@import 'mixin';
.text {
  @include singleline-ellipsis(600px);
}
.content-text {
  @include singleline-ellipsis(1000px);
}

媒体查询与 mixin

@mixin ipad {
  @media screen and (min-width: 768px) {
    @content;
  }
}

.header {
  width: 1000px;
  @include ipad {
    width: 500px;
  }
}
.footer {
  color: red;
  @include ipad {
    color: blue;
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值