Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAurelian Spodarec
10,801 PointsCSS Grid System - Sass
HI, I want to make a grid system so e.g. when i write md or full-md-less or such, my current grid will change.
So right now, the collumns are all 100% width on mobile, and if they pass mobile, they are as much columns, as i set, so tablet is 3 say, and i need to put to be desktop 4, but they wont, since there is only one value.
What would be a good way to do this? theres my css
// ==========================================================================
// Grid Container
// ==========================================================================
.grid {
content: "";
display: table;
clear: both;
float: none;
width: 100%;
// Make nested grid 100%
[class*="grid__col--"] > & {
width: 100%;
}
// Set a max-width for grid container
@media (min-width: 1100px) {
max-width: $g-cont-max-w;
}
}
// ==========================================================================
// Grid Columns
// ==========================================================================
// Calculate grid columns
@media (min-width: 769px) {
@for $i from 1 through $g-col-count {
$context: g-context($g-col-width, $g-col-count ,$g-gutter-width) !global;
$target: ($g-col-width * $i) + ($g-gutter-width * ($i - 1));
// Generate column modifier classes
.grid__col--#{$i} {
width: percentage($target / $context);
}
}
}
// Column styles
[class^="grid__col--"] {
@media (min-width: 1px) and (max-width: 768px) {
margin-top: em(12px);
margin-bottom: em(12px);
}
@media (min-width: 769px) {
@include doubly(percentage($g-gutter-width / $context));
float: left;
min-height: 1px;
&:last-of-type {
float: right;
}
}
}
.full-md-less {
@include mq(medium-less) {
width: 100%;
}
}
// ==========================================================================
// Mixins
// ==========================================================================
@if variable-exists(font-url) {
@import url($font-url);
}
@function g-context($g-col-width, $g-col-count ,$g-gutter-width) {
$g-context: ($g-col-width * $g-col-count) + ($g-gutter-width * ($g-col-count - 1));
@return $g-context;
}
//Media queries
@mixin mq($break) {
@if $break == "small" {
@media (min-width: $brk-sm) and (max-width: $brk-md) {
@content;
}
}
@else if $break == "medium-less" {
@media(max-width: $brk-lg){
@content;
}
}
@else if $break == "medium" {
@media(min-width: $brk-md + 1){
@content;
}
}
@else if $break == "large" {
@media(min-width: $brk-lg){
@content;
}
}
@else {
@error "Error, No value could be retrieved for '#{$break}' "
}
}
@mixin doubly($margin: 1em) {
& + & {
margin-left: $margin;
@content;
}
}
// Grid
$g-col-width : 65px;
$g-gutter-width : 30px;
$g-col-count : 12;
$g-cont-max-w : 1100px;
// Breakpoints
$brk-sm : 1px;
$brk-md : 768px;
$brk-lg : 1080px;