Help me out you sassy susy's, I am at my breaking point! I am trying to make the most efficient layout for my project, and I have come across something I havn't been able to figure out with Susy/breakpoint.
I want the layout columns to change at the breakpoints and not have to change all the individual spans of the div's (as there will be many different span widths with this way. Instead of just 1 and changing 3 or 4 different column layouts).
Right now the only way I was able to get this to work was by changing the spans of the divs and keeping the columns unchanged, but I would like the divs to always stay the same size and then just drop into place depending on how many columns are left to fill.
I think it is just the way I am writing the #include. I have tried doing container/layout inside the breakpoint instead of with-layout with no success.
I know this is probably going to be a simple fix that I am just not seeing.
Edit: Also something I have noticed is that no matter how I change things the div is always taking the default $susy map and is not changing it at breakpoint.
SCSS:
#import 'susy';
#import 'breakpoint';
$layout1: layout(12 .125 split fluid center);
$layout2: layout(16 .125 split fluid center);
$layout3: layout(24 .125 split fluid center);
.container {
#include container;
#include with-layout($layout1);
background: orange;
#include breakpoint(600px) {
#include with-layout($layout2);
background: red;
}
#include breakpoint(1000px) {
#include with-layout($layout3);
background: blue;
}
}
.testbox {
#include span(1);
}
html:
<div class="container">
<div class="testbox">hello</div>
<div class="testbox">hello</div>
<div class="testbox">hello</div>
<div class="testbox">hello</div>
<div class="testbox">hello</div>
<div class="testbox">hello</div>
<div class="testbox">hello</div>
<div class="testbox">hello</div>
</div>
with-layout only changes the settings used for Susy mixins/functions nested inside it:
#include with-layout($layout2) {
// code nested here will use the $layout2 settings
}
You have nothing nested inside any call to with-layout - therefor no changes. This is exactly what #cimmanon was trying to explain in the comments. Similarly, #media only changes things nested directly inside it — so your colors change fine, but your spans don't. The colors are actually nested, the spans aren't.
Because Sass is pre-processed, span(1) cannot have multiple outputs unless it is called multiple times. Right now you call it once, so it has one output. If you call it multiple times inside different layout contexts, you can get different outputs.
// This will give you different spans at different breakpoints:
#include breakpoint(600px) {
#include with-layout($layout2) {
#include span(1);
background: red;
}
}
// you can also use the susy-breakpoint shortcut:
#include susy-breakpoint(1000px, $layout3) {
#include span(1);
background: blue;
}
Related
I'm pretty new to Sass and I want to depending on certain condition use one css class or another...
Basically if my #media has size #media width:320px I would like to use bootstrap's col-xs-12 and #media has size width:480px then bootstrap's col-xs-6. I've tried to accomplish that by #extend these two classes within #media, but It wont compile.
There is a way to declare a variable and use it in classname?
Something like that:
$my-class: none;
#media (min-width:320px) {
$my-class: col-xs-12;
}
#media (min-width:480px) {
$my-class: col-xs-6;
}
And in my html:
<div class="row">
<div class="col $my-class"><!--Replace with the value of this variable.-->
</div>
</div>
I've read some material of Sass, but like a said, I'm very, very new to it.
I don't know if I'm asking correctly or even if make sense...
Your syntax is a bit off for SASS, but the root of the problem, is that you need to extend or include bootstraps classes. The col-xx-xx classes are actual media queries, so you are essentially placing a media query within a media query.
You want to do this for your SASS:
.row {
.col {
#extend .col-xs-12;
#extend .col-sm-6;
}
}
You don't need the special class for the .col unless you need to apply styles to elements with that class only.
So, your SASS could look like this:
.row {
.your-class {
#extend .col-xs-12;
#extend .col-sm-6;
}
}
Your HMTL
<div class="row">
<div class="col your-class"></div>
</div>
As the other answer posted, SASS doesn't directly affect your HTML and cannot read variables in your HTML. You simply need to use classes like normal CSS as SASS just gets processed to CSS.
As a note! For this to work you must include bootstrap in your SASS file so the preprocessor has access to the variables:
Your SASS file (at the top):
#include 'bootstrap.scss' <-- or wherever your bootstrap SASS files live
Hopefully this helps.
Sass can't access or modify HTML markup. It can only compile to a static CSS file.
Using Bootstrap's grid, you should be able to include column classes for each breakpoint, e.g. col-xs-12 col-sm-6 to get 12 columns # the xs breakpoint and 6 columns # the sm breakpoint.
Alternatively, if you're using Boostrap v4 (still in alpha), you can use #include make-col(6) within your media queries to have a little more control and keep your markup classes more semantic.
I am very new to sass and i am trying to convert a bootstrap layout to bootstrap-sass so that i can have multiple "brands" use the same code-behind with different layouts.
I've managed to use variations of the following to have two versions with different grid structures:
.someclassname {
#include make-sm-column(6);
}
is there an equivalent for hidden-xs (perhaps something like #include make-hidden(xs)?
The idea being one site might have a div hidden on mobile but the other site would want the same div visible.
You can do the following
.someclass {
#extend .hidden-xs;
}
I have a 24 Susy column grid. I'm trying to do some boxes that will each span 6 columns (so 4 per row), but I'm wanting to add some gutters around them, withing a wider container that is 24 columns wide. Unfortunately, no matter what I try, I can't get it to work. It seems the columns are not adjusting their width to accommodate the gutters...I thought Susy was supposed to do that, no? I'm new to all of this so I've read lots of articles and posts and can't figure out this answer, so any help you can give is greatly appreciated.
Here's the code:
.solutionThumbnails {
#include span(24 no-gutters);
#include container;
#include clearfix;
li {
#include span(6);
#include gutters(8px after);
background: #666;
float: left;
height: 240px;
display: block;
&:nth-child(4) {
margin-right: 0px;
}
}
}
And here's what it's looking like right now, ignore the formatting otherwise, still coding :) (you'll see its knocking the fourth item down):
http://i.stack.imgur.com/5tmWp.jpg
Because Sass isn't aware of the DOM, Susy doesn't know that your span and gutter mixins are being applied to the same element, or are related in any way. Susy will handle the math when it has all the information. I think you want something like this?
.solutionThumbnails {
#include container(24);
li {
#include gallery(6 of 24 split);
background: #666;
height: 240px;
}
}
I don't know your settings, or many specifics about the output you need, but that should get you close. You don't need to set a span, container, and clearfix on the same element — the container mixin handles all of that. Similarly, gallery handles everything you need for a consistent layout of same-sized items.
My example doesn't get you exactly 8px gutters. The only way to mix static (px) gutters with fluid (%) grids, is to move the gutters inside the elements. You can approximate 8px gutters with a fluid value by changing the gutter ratio as needed. The default ratio is .25.
It appears to me that the default behavior for Neat should be that each span column should have a margin (or gutter) between adjacent span columns. Every example that I've found online simply installs Neat, does a quick demo, and the result has a gutter between adjacent elements. No settings changed.
Would anyone know why that is not happening for me? I have a clean install of Bourbon and Neat. My html is as follows...
<footer class="col-2">
<section class="left">
content
</section>
<section class="right">
content
</section>
</footer>
My sass looks like...
.col-3 {
#include outer-container;
.left {
#include span-columns(6);
}
.right {
#include span-columns(6);
}
}
Here's a link to the rendered output:
So I actually have 2 questions.
Why are the columns stacked on top of each other, even if I float the left column?
Why are my columns ignoring the gutter between each column?
It looks like you misnamed your class (div has class .col-2 and scss has .col-3) and since you nested your classes the column mixin isn't applied to child div.
code works with matching class names here http://sassmeister.com/gist/0c1963fef94a14d5268f
The issue was related to my normalize stylesheet. Had some rules overriding Neat.
I need to make some elements of susy's gallery mixin span two columns, the problem is as shown in the picture it does not push the other elements after it, even though I tried to do that manually. How could this be done.
The link to the code https://github.com/iyedg/IGBlogTheme
Here is the perfect tutorial about gallery with different size items.
And the main point is: You can't achieve this with gallery() mixin, but it's possible with span() mixin by something like
$susy: (
columns: 12,
output: isolate
);
// Assuming output is set to isolate
.gallery__item {
margin-bottom: gutter();
#include span(4 of 12 split);
&:nth-child(4),
&:nth-child(7), {
width: span(8 of 12 split);
}
}