Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save joelstransky/fd97c93f86c71bdd9da11036959fa133 to your computer and use it in GitHub Desktop.

Select an option

Save joelstransky/fd97c93f86c71bdd9da11036959fa133 to your computer and use it in GitHub Desktop.
Bootstrap3 Fixed Width Columns mixin
// demo: http://codepen.io/JoelStransky/pen/VKPVAG
// breakpoint list ('column type', 'screen breakpoint', 'container width @ break point')
$breakpoints: ( ('xs', $screen-xs, $screen-xs), ('sm', $screen-sm, $container-sm), ('md', $screen-md, $container-md), ('lg', $screen-lg, $container-lg) );
@mixin make-fixed-grid() {
@each $item in $breakpoints {
@media (min-width: #{nth($item, 2)} ) {
// background: red;
@include make-fixed-grid-columns( $grid-columns, nth($item, 1), width, nth($item, 3) );
}
}
}
@mixin make-fixed-grid-columns($columns, $class, $type, $break) {
@for $i from 0 through $columns {
@include calc-fixed-column-width($i, $class, $type, $break);
}
}
@mixin calc-fixed-column-width($index, $class, $type, $break) {
@if ($type == width) and ($index > 0) {
.col-#{$class}-fixed-#{$index} {
width: (($index / $grid-columns) * $break) - $grid-gutter-width;
}
}
}
// optional, use this to inject fixed widths to any class
@mixin make-fixed-widths( $class ) {
@each $item in $breakpoints {
@for $i from 1 through $grid-columns {
@include make-fixed-width(nth($item, 1), $i, $class);
}
}
}
@mixin make-fixed-width($size, $index, $class ) {
#{$class} {
.col-#{$size}-#{$index} & {
@extend .col-#{$size}-fixed-#{$index};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment