内容简介:Susy 2 教程 — 实战篇
在前面介绍了Susy2的配置(config)和简写(shorthand)之后,给大家介绍一下Tookit中几个常用的宏, 然后动手做一个 Bootstrap 栅格系统
Tookit
Susy 2 的 Tookit 是围绕我们的简写语法( shorthand )构建的。通过 shorthand 调整初始配置值来控制每一个细节,让你不会被束缚在一套栅格系统上。
常用Tookit
Span [mixin]
span 是一个高频度的混合宏,可以灵活设定元素的栅格位置。
- 语法格式: span($span) { @content }
- $span:
shorthand <span> - @content: Sass content block
//input scss
$susy: (
container:1000px,
column-width:100px,
math:static,
columns: 10, // The number of columns in your grid
gutters: .25, // The size of a gutter in relation to a single column
gutter-position:split
);
.col-left{
@include span(1);
}
.col-right{
@include span(2 last);
}
.col-half {
@include span(50%);
}
// ======= output css =========
.col-left {
width: 100px;
float: left;
margin-left: 12.5px;
margin-right: 12.5px;
}
.col-right {
width: 225px;
float: right;
margin-left: 12.5px;
margin-right: 12.5px;
}
.col-half {
width: 50%;
float: left;
margin-left: 12.5px;
margin-right: 12.5px;
}
susy-media [mixin]
susy-media 提供了基本的媒体查询,并内置在 susy-breakpoint 混合宏中。
- 语法格式: susy-media($query, $no-query)
- $query:
<min-width> [<max-width>] | <string> | <pair> | <map> - $no-query:
<boolean>|<string>
// input scss
@include susy-media(30em) {
background-color: #FFF;
}
// output css
@media (min-width: 30em) {
background-color: #FFF;
}
// input scss
@include susy-media(30em 60em) { /*...*/ }
// output css
@media (min-width: 30em) and (max-width: 60em) { /*...*/ }
// input scss
@include susy-media(min-height 30em) { /*...*/ }
// output css
@media (min-height: 30em) { /*...*/ }
susy-breakpoint [mixin]
susy-breakpoint 为混合宏 susy-media 或者第三方 breakpoint 插件提供不同媒体断点查询。
- 语法格式: susy-breakpoint($query, $layout, $no-query)
- $query: media query shorthand
- $layout:
shorthand <layout> - $no-query:
<boolean>|<string>
// input scss
$susy: (
container:1000px,
column-width:100px,
math:static,
columns: 10, // The number of columns in your grid
gutters: .25, // The size of a gutter in relation to a single column
gutter-position:split
);
@include susy-breakpoint(30em, 8) {
// nested code uses an 8-column grid,
// starting at a 30em min-width breakpoint...
.example { @include span(3); }
}
// output css
@media (min-width: 30em) {
.example {
width: 350px;
float: left;
margin-left: 12.5px;
margin-right: 12.5px;
}
}
更多的Tookit请查看官方文档 http://susydocs.oddbird.net/en/latest/toolkit/
创建一个 Bootstrap 栅格系统
| 超小屏幕 手机 (<768px)<small=""> | 小屏幕 平板 (≥768px) | 中等屏幕 桌面显示器 (≥992px) | 大屏幕 大桌面显示器 (≥1200px) | |
|---|---|---|---|---|
| 栅格系统行为 | 总是水平排列 | 开始是堆叠在一起的,当大于这些阈值时将变为水平排列C | ||
.container 最大宽度 |
None (自动) | 750px | 970px | 1170px |
| 类前缀 | .col-xs- |
.col-sm- |
.col-md- |
.col-lg- |
| 列(column)数 | 12 | |||
| 最大列(column)宽 | 自动 | ~62px | ~81px | ~97px |
| 槽(gutter)宽 | 30px (每列左右均有 15px) | |||
| 可嵌套 | 是 | |||
| 偏移(Offsets) | 是 | |||
| 列排序 | 是 |
全局配置
$susy:( debug:(image:show), // 开启debug columns:12, gutters: 0, gutter-position: inside, );
小于 768px 的适配
// 展示容器元素
.container-xs{
height: 200px;
@include container;
// 大于0 , 小于768px
@include susy-breakpoint(0 768px){
@include container;
}
}
[class^=col-xs]{
// PS:由于susy2的gutters只能设置百分比,不能给绝对值,因而选择另一种方式
// 当class前面有col-xs的文字时,则自动加上padding左右的设定。
padding-left: 15px;
padding-right: 15px;
background-color:rgba(#CFFFA3,.8);
border-right:3px #F94B22 solid;
text-indent:2em;
height:40px;
}
// col-xs 版
@for $i from 1 through 12 {
.col-xs-#{$i}{
@include span($i)
}
}
大于等于768px 的适配
// col-sm 版 : >= 768px
// 这里列宽为什么是32.5?而不是62呢?
// 道理很简单,因为 gutter-position:inside,会给元素设置 box-sizing:border-box
// layout shorthand :
// 12grids
// 32.5px columnWidth
// 30px gutterWidth
$SmallDevice:(12 (32.5px 30px) inside);
$breakSmallDevice: 768px; //设定断点
[class^=col-sm]{
background-color:rgba(#F959EB,.8);
border-right:3px #F94B22 solid;
text-indent:2em;
height:40px;
}
// 展示容器元素
.container{
height: 200px;
@include container;
@include susy-breakpoint($breakSmallDevice,$SmallDevice){
@include container;
}
}
@include susy-breakpoint($breakSmallDevice){
@for $i from 1 through 12 {
@include with-layout($SmallDevice){
.col-sm-#{$i}{
@include span($i);
}
}
}
}
// 以此类推,≥992px,≥1200px都同样可以实现。
效果图
通过这个例子,我们可以发现,制作一个栅格系统,用Susy2,只需要用到 span , container , susy-breakpoint , width-layout 就可以轻松制作出来。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- go语言实战教程:Redis实战项目应用
- 企业级区块链实战教程
- 【译】RabbitMQ 实战教程(五) 主题
- 【译】RabbitMQ 实战教程(四) 路由
- Python 机器学习实战教程:回归
- 【译】RabbitMQ 实战教程(三) 发布/订阅
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Intel汇编语言程序设计
Kip Irvine / 电子工业出版社 / 2007-9-1 / 61.00元
《国外计算机科学教材系列•Intel汇编语言程序设计(第5版)》全面细致地讲述了汇编语言程序设计的各个方面。从微处理器体系结构、工作机制到指令集;从最基本的编译器链器的使用到高级过程、结构和宏的使用;从用纯汇编编写程序到用C/C++等最新编译器与汇编的混合接口编程;从16位实模式下BIOS、DOS实模式文本及图形程序设计到32位保护模式的Windows程序设计;从磁盘基础知识到Intel指令编码、......一起来看看 《Intel汇编语言程序设计》 这本书的介绍吧!