我一直在試圖解決我的網格,我不知道爲什麼我的列不堆疊在一起。當我提出一個div容器和裏面一排,然後12列列正在整個寬度,則跑馬圈地下面用sass解決我的Grid問題?
$screen-width: 1147px;
$number-of-columns: 12;
$gutter: 30px;
$column-width: $screen-width/$number-of-columns;
$padding: $gutter/2;
$total-width: ($column-width * $number-of-columns) + ($gutter * ($number-of-columns - 1));
$gutter-width:($gutter/$total-width) * 100%;
@for $i from 1 through $number-of-columns {
.column-#{$i} {
width: ($i /$number-of-columns) * 100%;
background:#ccc;
float: left;
margin-left: $gutter;
}
}
@mixin clearfix() {
&:before,
&:after {
content: " "; // 1
display: table; // 2
}
&:after {
clear: both;
}
}
// Set Base Container
.container {
max-width:$total-width;
margin:0px auto;
padding: 0 $padding 0 $padding;
background: blue;
@include clearfix;
}
.row {
width: 100%;
margin: 0;
background: green;
@include clearfix;
}
不應盒大小:邊界盒;考慮寬度的排水溝? –
不,這意味着盒子的寬度是使用內容,填充和邊框寬度計算的,但不是邊距。 – jonhobbs
@jonhbbs我使用了yr建議並添加了一個函數來計算每列的寬度,我非常感謝你。 –