Scss,Sass之@if,@for
来源:互联网 发布:中文域名续费价格 编辑:程序博客网 时间:2024/05/23 13:13
Scss的强大毋庸置疑,而且传统的css编写也是让人头疼。
- Scss拥有强大的去重思想,css样式往往会产生大量的重复性代码
- Scss可以定义变量
- Scss可以进行数学运算
- Scss可以进行条件判断
- Scss可以进行循环
- Scss具有良好的结构特性
代码段
.total-vote-container { width: 2304px; height: 960px; background-image: url("/images/img_bg.jpg"); padding: 0; margin: 0; background-repeat: no-repeat; .total-vote-title { width: 516px; height: 113px; background: url('/images/program_rank.png') no-repeat; position: relative; left: 950px; top: 50px; } .total-vote-content { position: absolute; list-style:none; width: 1200px; height: 600px; margin-left: 740px; top: 203px; .program-record { width:600px; height:70px; vertical-align: middle; font-family: 微软雅黑; font-size: 45px; .program-index { height: 100%; color: #fff661; float: left; font-weight: bold; } .program-name { height: 100%; width: 300px; color: #fff; float: left; margin-left: 20px; white-space:nowrap; text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow: hidden; } .heart-img { float: right; height: 100%; margin-right: 15px; } .total-vote { float: right; color: #fff661; } } } @mixin change-style($index) { @if $index < 6 { margin-left: 120 * ($index - 1) + px;} @else if $index == 6 {margin-left: 120 * ($index - 1) + px; font-size: 40px !important;} } .foo { @include change-style(5); } @for $i from 2 to 4 { li:nth-child(#{$i}) { margin-left: 120 * ($i - 1) + px;} } @for $i from 4 to 6 { li:nth-child(#{$i}) { margin-left: 120 * ($i - 1) + px; font-size: 40px !important;} } @for $i from 6 to 8 { li:nth-child(#{$i}) { margin-left: 120 * (10 - $i) + px; font-size: 40px !important;} } @for $i from 8 to 11 { li:nth-child(#{$i}) { margin-left: 120 * (10 - $i) + px; font-size: 36px !important;} }}
总结
- 详细的语法讲解见sass中文文档
- 学会了scss将让你的代码变得非常优美
- 本篇主要讲解@if和@for通过上例,你应该可以发现,@if可以使用逻辑判断,但是不能这样使用(@else if index < 6 &&index > 3),我试过了。
- 本篇还有一些关于Css选择器的使用,如果你看不懂的话,可以参考Css选择器
0 0
- Scss,Sass之@if,@for
- webStorm 之sass/scss
- 前端之Sass/Scss实战笔记
- SASS学习系列之(一)--------- SASS,SCSS环境搭建(Ruby)
- SASS详解之控制指令(if、each、for和while)
- SASS学习系列之(二)--------- SASS,SCSS环境搭建(node-sass)
- SASS、SCSS介绍
- Sass跟Scss 上手
- sass 和 scss
- sass/scss学习笔记
- css3,scss和sass
- SASS/SCSS 使用指南
- sass/scss语法@mixin
- SASS和SCSS
- sass安装 scss安装
- SASS&&SCSS起步
- sass/scss、less
- Sass/Scss、Less是什么?
- WWDC 2014 笔记 - iOS界面开发的大一统
- 离散--第二节--证明方法
- dj java decompiler 反编译支持中文
- 互联网协议 网络通信
- java.lang.IllegalStateException: No activity
- Scss,Sass之@if,@for
- Web APP开发技巧总结
- C#获取文件版本、文件大小等信息
- Android录制mp3格式
- [JS插件] Swiper:强大的触摸滑动&整屏滚动插件
- NVIDIA cuda7在centos6.5中的安装
- 查看进程
- 在vim保存时获得sudo权限
- js中用$(“#ID”)来作为选择器的问题(id重复的时候)