sass06 mixin

scss

@mixin cont{    //mixin是关键字
    color:red;
}

body{
    @include cont;  //使用默认值
}

@mixin cont($color: red ){  //默认值
  color: $color;
}

body1{
    @include cont(#fff);  //传参数
}

@mixin cont($color: red, $fontSize: 14px){  //mixin是关键字
  color: $color;
  font-size: $fontSize;
}

body2{
  @include cont($fontSize: 18px);    //map方式传值
}

@mixin box-shadow($shadow...){    //多值参数
  -moz-box-shadow: $shadow;
  -webkit-box-shadow: $shadow;
  box-shadow: $shadow;
}

.shadows{
  @include box-shadow(0px 4px 4px #555, 2px 6px 10px #6dd3ee);
}

@mixin style-for-iphone{
  @media only screen and (min-device-width: 320px) and (max-device-width:568px){
    @content;    //下面的font-size: 12px;
  }
}

@include style-for-iphone{
  font-size: 12px;
}

css

body {
  color: red;
}

body1 {
  color: #fff;
}

body2 {
  color: red;
  font-size: 18px;
}

.shadows {
  -moz-box-shadow: 0px 4px 4px #555, 2px 6px 10px #6dd3ee;
  -webkit-box-shadow: 0px 4px 4px #555, 2px 6px 10px #6dd3ee;
  box-shadow: 0px 4px 4px #555, 2px 6px 10px #6dd3ee;
}

@media only screen and (min-device-width: 320px) and (max-device-width: 568px) {
  font-size: 12px;
}

/*# sourceMappingURL=demo1.css.map */
时间: 2024-08-10 23:13:19

sass06 mixin的相关文章

从mixin到new和prototype:Javascript原型机制详解

这是一篇markdown格式的文章,更好的阅读体验请访问我的github,移动端请访问我的博客 继承是为了实现方法的复用,如何实现方法的复用呢?最容易想到的,就是: ```js//mixinfunction extend(optional, base){ for(var prop in base){ if(!prop in optional){ optional[prop] = base[prop] } } return optional}``` 这种方法俗称`mixin`,它直接从甲对象复制方

(十四)模块(Module)的补充、Mix-in

(1)Module和Class的关系.Module和Namespace的关系,Devise #查看一个类的父类,第二个说明类继承自模块(模块是类的父类)puts String.superclass,Class.superclass,Module.superclass #ruby没有命名空间的概念,用来避免与隔绝重复变量名和类名等等,ruby模块作用就是命名空间#rails开发时,Devise库用来做用户信息验证的,比如用户加密,登陆过后自动更新ip地址登陆时间等#Devise是个大模块,里面又包

bootstrap作为mixin库的应用模式

Bootstrap作为一个非常流行的前端css框架,得到了非常多的应用.一般的使用方法都是直接download bootstrap.css,作为css文件引入到html的markup中,随后直接引用其定义的class,这样的使用模式有个问题:考虑下面的场景,你需要设计一个login form,在该表单中有一个button,通常情况下,你在html markup中使用.btn,.btn-primary预置的class.虽然没有什么大的问题,但是html本身不具有表意性.如果我们既要使用到boots

Ruby学习之mixin

直接上代码: module Action def jump @distance = rand(4) + 2 puts "I jumped forward #{@distance} feet!" end end class Rabbit include Action attr_reader :name def initialize(name) @name = name end end class Cricket include Action attr_reader :name def i

React组件-mixin

一.组件 二.代码 1 <!DOCTYPE html> 2 <html lang="zh-cn"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Mixin</title> 6 </head> 7 <body> 8 <script src="./react-0.13.2/react-0.13.2/build/reac

React.js学习笔记(一):组件协同与mixin

组件协同: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>父子关系</title> </head> <body> <script src="react.js"></script> <script src="JSXTran

sass中mixin常用的CSS3

圆角border-radius 1 @mixin rounded($radius){ 2 -webkit-border-radius: $radius; 3 -moz-border-radius: $radius; 4 border-radius: $radius; 5 } 盒模型阴影box-shadow 下面是一个使用多参数的例子:用CSS3创建一个阴影的mixin,需要传递水平和垂的偏移量,模糊的范围,还有颜色,4个参数: 1 @mixin shadow($x, $y, $blur, $co

sass中常用mixin

//设置字体大小 @mixin font($s:14px,$h:1.5,$f:microsoft yahei){ font:$s/#{$h} $f; } //设置水平居中 @mixin horizontal-center { margin-left: auto; margin-right: auto; } //参数(方向,大小,颜色),默认:向下,10px,红色 %arrow{ width:0; height:0; line-height:0; font-size: 0; overflow:hi

[SCSS] Reuse Styles with the SCSS @mixin Directive

Copy/pasting the same code is redundant and updating copy/pasted code slows development velocity. Mixins are reusable chunks of code that are included, similar to calling a function, instead of copy/pasted. Mixins have some nice features:- Arguments