mixin.scss

//-----------------------------------浏览器前缀-----------------------------------------
//例子:@include css3(transition, 0.5s);
@mixin css3($property, $value) {
@each $prefix in -webkit-,
-moz-,
-ms-,
-o-,
'' {
#{$prefix}#{$property}: $value;
}
} //-----------------------------------Retina图片-----------------------------------------
@mixin image-2x($image, $width, $height) {
@media (min--moz-device-pixel-ratio: 1.3), (-o-min-device-pixel-ratio: 2.6/2), (-webkit-min-device-pixel-ratio: 1.3), (min-device-pixel-ratio: 1.3), (min-resolution: 1.3dppx) {
/* on retina, use image that's scaled by 2 */
background-image: url($image);
background-size: $width $height;
}
} //-----------------------------------清除浮动-----------------------------------------
//引用例子:@include clearfix();
@mixin clearfix() {
&:before,
&:after {
content: "";
display: table;
}
&:after {
clear: both;
}
} //-----------------------------------Black和White-----------------------------------------
//特别声明,上面这个不属于Sass的Mixins范畴,是Sass的自定义函数功能。
//background:black(0.15);
//color:white(0.9);}
@function black($opacity) {
@return rgba(0, 0, 0, $opacity)
} @function white($opacity) {
@return rgba(255, 255, 255, $opacity)
} //-----------------------------------内阴影和外阴影-----------------------------------------
//引用例子:@include box-emboss(0.8, 0.05);
@mixin box-emboss($opacity, $opacity2) {
box-shadow: white($opacity) 0 1px 0, inset black($opacity2) 0 1px 0;
} //-----------------------------------行高-----------------------------------------
//引用例子:@include line-height (16);
@mixin line-height($heightValue: 12) {
line-height: $heightValue + px; //fallback for old browsers
line-height: (0.125 * $heightValue) + rem;
} //-----------------------------------隐藏文字-----------------------------------------
//引用例子:
//.logo{
// background: url("logo.png");
// height:100px;
// width:200px;
// @include hide-text;
//}
@mixin hide-text {
overflow: hidden;
text-indent: -9000px;
display: block;
} //-----------------------------------响应式断点-----------------------------------------
//引用例子:
//@include breakpoint(large) {
// width: 60%;
//}
//@include breakpoint(medium) {
// width: 80%;
//}
//@include breakpoint(small) {
// width: 95%;
//}
@mixin breakpoint($point) {
@if $point==large {
@media (min-width: 64.375em) {
@content;
}
}
@else if $point==medium {
@media (min-width: 50em) {
@content;
}
}
@else if $point==small {
@media (min-width: 37.5em) {
@content;
}
}
} //-----------------------------------正三角-----------------------------------------
//正三角的通用属性
%triangleBase {
_font-size: 0;
_line-height: 0;
_overflow: hidden;
width: 0;
height: 0; } //regulaTriangle:正三角(dashed默认透明)
//例子:@include regulaTriangle(top,red);
@mixin regulaTriangle($derection:bottom, $color: #000, $width: 20px) {
@extend %triangleBase;
border-width: $width;
//向右
@if $derection==right {
border-style: dashed dashed dashed solid;
border-color: transparent transparent transparent $color;
}
//向左
@if $derection==left {
border-style: dashed solid dashed dashed;
border-color: transparent $color transparent transparent;
}
//向上
@if $derection==top {
border-style: dashed dashed solid dashed;
border-color: transparent transparent $color transparent;
}
//向下
@if $derection==bottom {
border-style: solid dashed dashed dashed;
border-color: $color transparent transparent transparent;
}
} //-----------------------------------直角三角形-----------------------------------------
//right-angledTriangle:直角三角形
//例子:@include right-angledTriangle(1,red);
@mixin right-angledTriangle ($derection:1, $color:#000, $width: 20px, $opacity:transparent, $border:dashed) {
@extend %triangleBase;
border-width: $width;
//向右
@if $derection==1 {
border-style: $border dashed dashed $border;
border-color: $color $opacity $opacity $color;
}
//向右
@if $derection==2 {
border-style: $border $border dashed dashed;
border-color: $color $color $opacity $opacity;
}
//向右
@if $derection==3 {
border-style: dashed $border $border dashed;
border-color: $opacity $color $color $opacity;
}
//向右
@if $derection==4 {
border-style: dashed dashed $border $border;
border-color: $opacity $opacity $color $color;
}
} //-----------------------------------圆角-----------------------------------------
//radius:圆角
//例子:@include radius(24,100%);
@mixin radius($num:1234, $size: 5px) {
@if $num==1234 {
-webkit-border-radius: $size; //Saf3+, Chrome
-moz-border-radius: $size; //FF1+
border-radius: $size; //Opera 10.5, IE 9
-ms-border-radius: $size;
}
@if $num==12 {
-webkit-border-top-left-radius: $size;
border-top-left-radius: $size;
-webkit-border-top-right-radius: $size;
border-top-right-radius: $size;
-moz-border-top-left-radius: $size;
-ms-border-top-left-radius: $size;
-moz-border-top-right-radius: $size;
-ms-border-top-right-radius: $size;
}
@if $num==23 {
-webkit-border-top-right-radius: $size;
border-top-right-radius: $size;
-webkit-border-bottom-right-radius: $size;
border-bottom-right-radius: $size;
-moz-border-top-right-radius: $size;
-moz-border-bottom-right-radius: $size;
-ms-border-top-right-radius: $size;
-ms-border-bottom-right-radius: $size;
}
@if $num==34 {
-webkit-border-bottom-right-radius: $size;
border-bottom-right-radius: $size;
-webkit-border-bottom-left-radius: $size;
border-bottom-left-radius: $size;
-moz-border-bottom-left-radius: $size;
-moz-border-bottom-right-radius: $size;
-ms-border-bottom-left-radius: $size;
-ms-border-bottom-right-radius: $size;
}
@if $num==14 {
-webkit-border-top-left-radius: $size;
border-top-left-radius: $size;
-webkit-border-bottom-left-radius: $size;
border-bottom-left-radius: $size;
-moz-border-top-left-radius: $size;
-moz-border-bottom-left-radius: $size;
-ms-border-top-left-radius: $size;
-ms-border-bottom-left-radius: $size;
}
@if $num==13 {
-webkit-border-top-left-radius: $size;
-webkit-border-bottom-right-radius: $size;
-ms-border-top-left-radius: $size;
-ms-border-bottom-right-radius: $size;
border-top-left-radiu: $size;
-moz-border-top-left-radius: $size;
border-bottom-right-radiu: $size;
-moz-border-bottom-right-radius: $size;
}
@if $num==24 {
-webkit-border-top-right-radius: $size;
border-top-right-radius: $size;
-webkit-border-bottom-left-radius: $size;
border-bottom-left-radius: $size;
-moz-border-top-right-radius: $size;
-moz-border-bottom-left-radius: $size;
-ms-border-top-right-radius: $size;
-ms-border-bottom-left-radius: $size;
}
} //-----------------------------------边框阴影-----------------------------------------
//boxshadow:边框阴影
//例子:@include boxshadow(24,100%);
@mixin boxshadow($x: 3px, $y: 3px, $shadowcolor: #cccccc) {
-moz-box-shadow: $x $y 4px $shadowcolor; // FF3.5+
-webkit-box-shadow: $x $y 4px $shadowcolor; // Saf3.0+, Chrome
box-shadow: $x $y 4px $shadowcolor; // Opera 10.5, IE 9.0
filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$shadowcolor}');
/* IE6,IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$shadowcolor}')";
/* IE8 */
} //-----------------------------------透明度-----------------------------------------
//myOpacity:透明度
//例子:@include myOpacity(0.3,93,197,16);
@mixin myOpacity($opacity:0.5, $r:0, $g:0, $b:0) {
$xx: $opacity * 100;
filter: alpha(opacity=$xx);
background-color: rgba($r, $g, $b, $opacity); // rgba()和opacity都能实现透明效果,但最大的不同是opacity作用于元素,以及元素内的所有内容的透明度,而rgba()只作用于元素的颜色或其背景色.两种都不被IE支持(IE9开始支持)
//如果要兼容ie文字不透明,需要用元素把文字包裹起来,然后色值position:relative或者absolute。
//opacity: $opacity;//opacity属性是css3的属性,也可以实现透明效果,跟background-color: rgba同样效果。
}
//-----------------------------------透明度-----------------------------------------
//引用例子:@include opacity(0.8);
@mixin opacity($opacity) {
opacity: $opacity;
$opacity-ie: $opacity * 100;
filter: alpha(opacity=$opacity-ie); //IE8
}
//-----------------------------------动画keyframes生成-----------------------------------------
//动画keyframes生成
//例子:@include keyframes(动画名称);
//@include keyframes(move-the-object) {
// 0% {
// transform: translateX(0);
// }
// 100% {
// transform: translateX(200px);
// }
//}
@mixin keyframes($animationName) {
@-webkit-keyframes #{$animationName} {
@content;
}
@-moz-keyframes #{$animationName} {
@content;
}
@-o-keyframes #{$animationName} {
@content;
}
@keyframes #{$animationName} {
@content;
}
}

.

mixin的更多相关文章

  1. vue.mixin与vue.extend

    vue.mixin 全局注册一个混合,影响注册之后所有创建的每个 Vue 实例.谨慎使用全局混合对象,因为会影响到每个单独创建的 Vue 实例(包括第三方模板).大多数情况下,只应当应用于自定义选项, ...

  2. 用mixin引入模块后, 方法重名的解析方法

    关于mixin, 经常被问到一个问题是, 方法查找是如何处理的? 特别地, 如果类, 父类, 以及类所包含的mixin中, 都定义有相同名字的方法时, 会发生什么? 答案是, ruby首先会从对象的直 ...

  3. 组件嵌套+Mixin函数demo

    非DOM属性:1.dangerouslysetInnerHTML(xxs跨站攻击) 2.key 3.ref 编写组件嵌套 <!DOCTYPE html><html>  < ...

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

    从mixin到new和prototype:Javascript原型机制详解   这是一篇markdown格式的文章,更好的阅读体验请访问我的github,移动端请访问我的博客 继承是为了实现方法的复用 ...

  5. sass揭秘之@mixin,%,@function

    因为文章内含有很多sass代码,如需自己动手查看编译结果,推荐使用sassmeister这款在线编译工具,方便你阅读学习. 在阅读本文章之前,请先确认你已经阅读了上篇文章sass揭秘之变量,不然会给你 ...

  6. 你的 mixin 兼容 ECMAScript 5 吗

    原文:Are your mixins ECMAScript 5 compatible? 作者:Nicholas C. Zakas 我最近在与客户合作的项目中,需要充分利用的 ECMAScript 5, ...

  7. Design Pattern: Not Just Mixin Pattern

    Brief 从Mix-In模式到Mixin模式,中文常用翻译为“混入/织入模式”.单纯从名字上看不到多少端倪,而通过采用Mixin模式的jQuery.extend我们是否可以认为Mixin模式就是深拷 ...

  8. mixin设计模式

    mixin可以轻松被一个子类或者一组子类继承,目的是函数复用.在js中,我们可以将继承MiXin看作为一种通过扩展收集功能的方式. e.mixin = function(t) { for (var i ...

  9. Ruby学习之mixin

    直接上代码: module Action def jump @distance = rand(4) + 2 puts "I jumped forward #{@distance} feet! ...

  10. 我的常用mixin 之 lines

    /** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...

随机推荐

  1. cloc 统计代码行数工具

    cloc 统计代码行数工具 官网地址:http://cloc.sourceforge.net/ 下载完成后 会生成一个.exe文件 需要修改文件名为 cloc.exe 然后把这个文件拷贝到需要统计的根 ...

  2. LNMP 1.2升级Nginx、MySQL/MariaDB、PHP教程

    一般情况下不建议对生产环境进行升级,升级开始后会停止LNMP相关服务.本文仅适用于LNMP1.2及以后版本! 在LNMP目前LNMP v1.2中已经包含了Nginx.MySQL/MariaDB.PHP ...

  3. HDU 5280 Senior&#39;s Array 最大区间和

    题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...

  4. dmesg命令的使用

    dmesg命令用于打印Linux系统开机启动信息,kernel会将开机信息存储在ring buffer中.您若是开机时来不及查看信息,可利用dmesg来查看(print or control the ...

  5. [Asp.net MVC]页面伪静态实现

    摘要 从页面Url及页面名称上看,你会发现静态页面和伪静态是一样的.伪静态的页面后缀可能是html,htm,cshtml等,只是改变了url的表现形式,实际上还是动态的页面.在SEO方面,伪静态和静态 ...

  6. [MySql]windows下设置mysql默认编码

    摘要 在安装好mysql的时候,如果新建数据库或者表默认的编码为latin1,如果这时候插入中文时,出出现类似下面的乱码的问题. SQLException: Incorrect string valu ...

  7. SQLite使用EF6的连接配置

    在配置文件中配置连接字符串 1. 使用nuget安装SQLite Install-Package System.Data.SQLite 安装好后的依赖项有: System.Data.SQLite.dl ...

  8. CSS Flex布局属性整理

    Flex布局 display: flex; 将对象作为弹性伸缩盒展示,用于块级元素 display: inline-flex; 将对象作为弹性伸缩盒展示,用于行内元素 注意兼容问题: webkit内核 ...

  9. IDC门外汉-单线、双线、智能多线、BGP的区别

    一.单线在此不多说,不是电信,就是网通机房,是,2005年前的机房情况: 二.双线:上般是从2004年到2008年用此方法较多,此今还有不少在用此法如下: 双线主机 有单IP和单网卡双IP地址,双网卡 ...

  10. 别忽视UIImage中的方向属性, imageOrientation-转

    转 : 别忽视UIImage中的方向属性, imageOrientation