Nested grids with breakpoints - sass

I want to use susy for two nested grids. One that defines the page layout (menu on the left, content on the right) and one inside content.
Reason for that is that the content is created by a CMS where different templates can be used and I'd like to have the scss code together with the template. Using a fluid grid seems to solve exactly that problem:
<div class="page">
<div class="menu">
<ul><li>foo</li><li>bar</li></ul>
</div>
<div class="content">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</div>
#import "susy";
/* Outer Grid (Page Layout) */
$total-columns : 4;
$column-width : 1024px / $total-columns;
$gutter-width : 0px;
$grid-padding : 0px;
.page {
#include container;
.menu {
#include span-columns(1);
}
.content {
#include span-columns(3);
}
}
/* Inner Grid */
$total-columns : 1;
$column-width : 200px;
$gutter-width : 0px;
$grid-padding : 0px;
$container-style: fluid;
.page .content {
#include container;
.item {
#include span-columns(1);
}
#include at-breakpoint(3) {
#include container;
.item {
#include span-columns(1);
}
}
}
My problem is the $column-width: 200px; for the inner grid, as the generated media query uses min-widht: 600px, although at this point there is only 75% width available.
What's the best way to implement this?

The container mixin doesn't do anything useful in a nested context. It sets a max-width and auto margins (for page centering) - both of which are already taken care of by your outer container.
I also recommend against 1-column grids. Start with your smallest useful grid (3), and just don't use the columns until you get past your mobile breakpoint.
It will become more clear in Susy 2.0, but column and gutter widths are mainly used to create a ratio - so the units you use don't matter much if you want to set them based on container width. That may sound confusing, but here's how I would achieve what you want:
$total-columns : 4;
$column-width : 200px;
$gutter-width : 0px;
$grid-padding : 0px;
$container-width: 1024px;
Based on those settings, Susy creates 4 columns without gutters, divided evenly from the available 1024px container-width. Since you set the $container-width, Susy is using $column-width and $gutter-width to determine a ratio - and since one side of that ratio is 0, it doesn't matter what the other side is, as long as it's something. The other use of those values is for calculating breakpoints. We'll see that a bit later. Now you can do your things:
.page {
#include container;
.menu {
#include span-columns(1);
}
.content {
#include span-columns(3 omega);
}
}
and:
.page .content {
.item {
// Elements span the full width by default, so nothing is needed in mobile view.
#include at-breakpoint($total-columns) {
#include span-columns(1,3);
#include nth-omega(3n);
}
}
}
The settings for the outer grid work just fine for the inner grid as well. They aren't actually different grids, just elements nested inside other elements.

Related

Full width container with fix width content. Sass, Bourbon Neat

I wish to make my background full width, with a image or colour background filling the row. However, I would like the content to sit in the middle spanning the standard 12 cols dictated by neat.
Currently my structure is:
<div class="container">
<section id="section">
<div class="left-col">
<p>some text</p>
</div>
<div class="right-col">
<p>some text</p>
</div>
</section>
</div>
With the relevant sass being:
.container
+outer-container(100%)
background-color: #fff
padding: 40px 0
#lead-text
+span-columns(12)
.left-col
+span-columns(4)
.right-col
+span-columns(8)
This results in the container spanning the full width of the browser. But so does the inner section? I would like this to sit in the centre across the standard 12 cols?
Thanks in advance
Keeping your current HTML I would do the following in SCSS:
.container {
background-color: pink;
}
#section {
#include outer-container;
background-color: #fff;
}
div.left-col {
#include span-columns(4);
}
div.right-col {
#include span-columns(8);
}
This makes the section the element neat treats as the outer-container, leaving the .container element to do it's natural thing of spanning the full browser window width, allowing you to add a background.
If I get your question right you want to do a "break-out-of-parent"
HTML
<div class="container">
<div class="break-out">Content</div>
</div>
CSS
// use border-box to prevent padding from
// being added to width (alway do this)
html { box-sizing: border-box; }
*,*:before,*:after { box-sizing: inherit; }
// the container is aligned center with
// a maximum width of xxx (doesn't matter)
.container {
margin: 0 auto;
max-width: 960px;
}
// breaking out of the container
.break-out {
// set the width to full screen width
width: 100vw;
// use calc to pull content back to the center
margin-left: calc(50% - 50vw);
// to make the content re-align with the container
// use the reversed calc to set padding
padding-left: calc(50vw - 50%);
}

Get the width of grid columns from within a div of changing width in susy

New to susy and can't find an answer to this simple question:
Here's the html structure:
<div class="wrap">
<div class="sidebar">
<h2>element</h2>
</div>
<div class="main"></div>
</div>
and here my basic susy settings and layout:
$susy : (
columns : 16,
gutters : 0,
global-box-sizing : border-box
);
#include global-box-sizing;
.wrap {
#include container;
}
.sidebar {
position: fixed;
top:0;
left:0;
width: span(1);
height: 100vh;
transition: width 0.3s ease;
}
.sidebar:hover {
width: span(4);
}
.main {
margin-left: span(1);
#include span (15 of 16);
transition: margin-left 0.3s ease;
}
.pushed {
margin-left: span(4);
}
Basically, the sidebar expands from 1 to 4 columns on hover and the main div gets pushed accordingly.
I need to add a margin or padding of 1 column to an element within .sidebar so that it is invisible until the sidebar expands. However, if I use .sidebar h2 { #include prefix(1 of 1)} the padding expands together with the sidebar and never gets shown. And if I use margin-left:span(1) instead, I get a very small value (1/16th of the sidebar width?).
How can I get the value of the width of the grid (i.e. span(1)) from within .sidebar?
I guess you need something like this .sidebar:hover h2 { #include prefix(1 of 4); }.
Since your Susy math is fluid, values are percentage based and depend of the context they are in. So by changing width from span(1) to span(4) you are changing context for all inner elements.
By the looks of your markup and code I will assume you are trying to build off-canvas navigation thingy? In that case I would suggest doing something like this
.sidebar h2 {
transform: translateX(100%);
transition: transform .3s ease;
}
.sidebar:hover h2 {
transform: translateX(25%); // 1/4 of the sidebar width
}

Singularity Grid layout with header and footer width 100%

I am using Singularity Grid System version 1.1.2, my variables for the 12 column grid are $grids: 12, $gutters: 1/3. The grid layout is working fine. Now I want to give the top Headergroup, middle section and the footer background color that covers the full browser width. All the content are centered and spans 90% of the total width.
Creating full color bleeds is an unfortunately ugly task all around, but it's fairly easy to do. You're going to want to do something like the following:
<div class="full-stripe header">
<header class="container"></header>
</div>
<div class="full-stripe main">
<main class="container"></main>
</div>
<div class="full-stripe footer">
<footer class="container"></footer>
</div>
What you need to do is wrap each section of your site in a div that will stretch the whole width of your page, while keeping the contained content pieces within it sharing a similar class. Your CSS would then look something like the following:
.full-stripe {
width: 100%;
#include clearfix;
&.header {
background: red;
}
&.main {
background: green;
}
&.footer {
background: blue;
}
}
.container {
margin: 0 auto;
padding: 0;
max-width: 68.5em;
#include clearfix;
}
I've created a CodePen to demonstrate the point. The container has a little bit of extra styling to make it stand out and help visualize what's going on:
Code
Full
You may find the nested context mixin in toolkit useful. It finds the context of percentage containers so #include nested-context(90%, center) on your hgroup will make it full width.

Sass multi-state navigation bar issue

I have a navigation bar, where the buttons have a hover state but also need to be "active" on their respective page. Since this navigation bar is part of an include, I decided to do the active state via a class on the body tag, as in .dashboard .dashboard-button. So I have the hover and this.
I was trying to figure out the most streamlined way to do this with Sass/Compass. I created a couple of mixins:
#mixin nav-button-on($icon) {
background-color: #2f3684; // Old browsers
#include filter-gradient($offwhite, #E5E5E5, vertical); // IE6-9
#include background-image(url('../images/'+$icon+'-on.png'),linear-gradient(top, $offwhite 0%, #E5E5E5 100%));
border-bottom: $borderbottom solid #F31A35;
a { color: $red;}
}
#mixin nav-button($icon){
background-color: #fff; // Old browsers
#include filter-gradient(#fff, #fff, vertical); // IE6-9
#include background-image(url('../images/'+$icon+'.png'),linear-gradient(top, #fff 0%, #fff 100%));
}
And then in the LI where the buttons are defined, I have
li {
&.dashboard {
#include nav-button('dashboard');
}
.dashboard &.dashboard {
#include nav-button-on('dashboard');
&:hover {
#include nav-button-on('dashboard');
}
}
}
HTML:
<body class="dashboard">
<div id="nav">
<ul>
<li class="first dashboard">Dashboard</li>
<li class="challenges">Challenges & Teams</li>
<li class="goals">Goals</li>
<li class="activity">My Activity</li>
<li class="destinations">Destinations</li>
<li class="fitness last">Fitness Resources</li>
</ul>
</div>
This seems a bit convoluted, I was wondering if anyone had any advice to streamline this at all.
NOTE: I had to add the white-to-white gradient, since when hovering over a solid-color background with the gradient hover state caused a flash.
There are a number of things to improve here:
Are you really dealing with that hierarchy of dashboard classes? For example, you're currently compiling to:
li.dashboard {
...
}
li .dashboard li.dashboard {
...
}
This seems wrong or at least poorly structured. Perhaps you could simplify things here.
Assuming you need this for each of your nav <li> elements, DRY it up with an iterated mixin:
li {
#each $item in dashboard, challenges, goals, activity, destinations, fitness {
&.#{$item} {
#include nav-button($item);
}
.#{$item} &.#{$item} {
#include nav-button-on($item);
&:hover {
#include nav-button-on($item);
}
}
}
}
But #2 is not actually the best way. Use placeholders rather than mixins for this kind of stuff, or combine the two. I'd do something like this:
%nav-button {
background-color: #fff; // Old browsers
#include filter-gradient(#fff, #fff, vertical); // IE6-9
}
%nav-button-on {
background-color: #2f3684; // Old browsers
#include filter-gradient($offwhite, #E5E5E5, vertical); // IE6-9
border-bottom: $borderbottom solid #F31A35;
a { color: $red;}
}
#mixin li-image($icon) {
#include background-image(url('../images/'+$icon+'.png'),linear-gradient(top, #fff 0%, #fff 100%));
}
#mixin li-image-on($icon) {
#include background-image(url('../images/'+$icon+'-on.png'),linear-gradient(top, $offwhite 0%, #E5E5E5 100%));
}
#each $item in dashboard, challenges, goals, activity, destinations, fitness {
body.#{$item} li, li.#{$item}:hover {
#extend %nav-button-on;
#include li-image-on($item);
}
li.#{$item} {
#extend %nav-button;
#include li-image($item);
}
}
Compare the outputs and maintainability of these and I think you'll find this quite a bit more streamlined!
You have a wrong } after #include nav-button('dashboard');
try it:
li {
&.dashboard {
#include nav-button('dashboard');
.dashboard &.dashboard {
#include nav-button-on('dashboard');
&:hover {
#include nav-button-on('dashboard');
}
}
}
}

Responsive images get unresponsive when trying to enlarge the browser window

Somehow it seems i run into issues on that image matrix example again and again i deal with in combination with Susy. :/ In preparation of finishing the project by applying media queries to it making things responsive i initially inspected the current state and resized the browser window. There happened the following:
https://dl.dropbox.com/u/8578/Resize.mov
Both shown image matrices consist of raster images. The black image matrix resizes and enlarges without a problem. But the second matrix has issues on enlarging again. Is that a plain CSS issue or more Susy related? And is there a way to fix it? :/
The basic Susy settings are:
$total-columns: 24;
$column-width: 3%;
$gutter-width: 1%;
$grid-padding: 0;
For images the following was applied:
img{
width:100%;
max-width: 100%;
height:auto !important;
}
The HTML part for the first matrix looks like that (i've entered only one li element - the other 27 differ only in title and linked images):
<ul class="customers sectionwrap">
<li><a><img title="Company" src="img/logo.png" alt="Logo" /></a></li>
</ul>
The Susy and layout relevant CSS parts for the first matrix (7x4) look that way:
.customers {
#include with-grid-settings($gutter: 0.1%){
li {
margin-right: -100%;
#include span-columns(2,14);
#include nth-omega(7n);
#for $g from 1 through 28
{
&:nth-child(#{$g}){#include push(0);}
}
}
}
}
The HTML part for the second matrix looks like that (i've entered only one li element - the other 8 differ only in title and linked images):
<ul class="moodlegrid sectionwrap">
<li><a class="ajax1" href="projekt1.html"><img title="Projekt1" src="img/1.jpg" alt="Projekt1" /><img title="Projekt1" src="img/2.jpg" alt="Projekt1" /><span class="spiceup">Zum Projekt</span></a></li>
</ul>
The Susy and layout relevant CSS parts for the second matrix (3x3) look that way - they are split because they are located in different partials:
.moodlegrid{
#include with-grid-settings($gutter: 0.8%){
li{
margin-right: -100%;
#include trailer(1 / 2);
#include span-columns(6,18);
#include nth-omega(3n);
#for $i from 1 through 9
{
&:nth-child(#{$i}) {#include push(0);}
}
}
}
}
.moodlegrid{
li{
a{
position: relative;
float:left;
display:block;
img:nth-child(1){
float:left;
display:block;
}
img:nth-child(2){
display: none;
}
span{
display:none;
}
}
a:hover{
img:nth-child(2){
display: block;
position: absolute;
z-index: 100;
top:0;
left:0;
}
span{
display: block;
position: absolute;
text-align:center;
top: 42%;
left: 34%;
z-index:101;
padding: 0.24em;
#include border-radius(5px, 5px);
#include box-shadow(black 2px 2px 10px);
}
}
}
}
I'd bet that your problem comes from floating the a tags that wrap the images. When you float something it creates a new layout context. If you don't set a width, the float collapses to the smallest possible size. Your img setting width: 100%; is figured as 100% of the collapsing a rather than 100% of the li. You can either remove the float or set width: 100%; on the a as well.

Resources