Skip to content

Instantly share code, notes, and snippets.

@viko16
Created March 2, 2016 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viko16/e86769bfebc41e2b00bd to your computer and use it in GitHub Desktop.
Save viko16/e86769bfebc41e2b00bd to your computer and use it in GitHub Desktop.
百分比网格布局 #stylus
// Grid
.row
margin-bottom: 2%
&:after
clear: both
&:before, &:after
content: " "
display: table
[class*=col-]
display: block
float: left
width: 100%
min-heigth: 1px
margin-left: 2%
&:first-child
margin-left: 0
// Function
cal-cols-width(index, total = 12)
return ((100 - (total / index - 1) * 2) / (total / index))
// Columns
cols-total = 12
for num in (1..cols-total)
.col-{num}
width: cal-cols-width(num, cols-total) + '%'
// Offsets
for num in (1..cols-total - 1)
.offset-{num}
// 非首项需要加 2% 的间隔
if num == 1
margin-left: cal-cols-width(num, cols-total) + '%'
else
margin-left: cal-cols-width(num, cols-total) + 2 + '%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment