Susy grid - any (easy?) way to make 'columns' the same height? - sass

Getting my feet wet with Susy/sass/haml etc (using adjusted middleman - with latest susy from master branch)
Have this in grid.css.scss
#import 'susy';
$total-columns : 8;
$column-width : 4em;
$gutter-width : 0em;
$grid-padding : $gutter-width;
$break-max : 12;
$container-style: magic;
// Container
.page {
#include container($total-columns, $break-max);
}
// Layout
.header {
#include at-breakpoint($break-max) {
#include pad(1,1);
}
}
.pagenav {
clear: both;
#include at-breakpoint($break-max) {
#include pad(1,1);
}
}
.main {
clear: both;
.main-left {
#include span-columns($total-columns omega);
#include at-breakpoint(10) {
#include span-columns(7);
}
}
.main-right {
#include span-columns($total-columns omega);
#include at-breakpoint(10) {
#include span-columns(3 omega);
}
}
#include at-breakpoint($break-max) {
#include pad(1,1);
}
}
.footer {
clear: both;
#include at-breakpoint($break-max) {
#include pad(1,1);
}
}
this snippet comes from site.css.scss
.main {
background-color: #eee;
}
.main-left {
background-color: #fff;
}
.main-right {
background-color: #eee;
}
.body background is black...
Now when content in main-left is larger than main-right I see a black square on the bottom right...
Any way I can make that bottom right #eee i.o.w. main-right the same height (dynamic) as main-left - or have the .main background to apply...???
Thanks
Peter
PS Somebody with more credits should make a Susy tag in stackoverflow...

#main {
display: table;
background-color: #eee;
}
.main-left,
.main-right{
display: table-cell;
vertical-align: top;
}
.main-left {
background-color: #fff;
}
.main-right {
background-color: #eee;
}
This will make the two divs match each other as if they were adjacent table cells.
Don't worry, this doesn't qualify as using tables for layout, it's cool for columns, and it's not caused me any problems.
Of course, shitty old browsers don't support it, but you could use a .js script like ie9.js to patch it where necessary.

Related

If mixins in empty show default

Is it possible to have a mixin that can override a current code block? I want to have it so that if the #mixin is empty the background for the box would be empty and then show in orange, but when I remove the #mixin it does not change to orange? What am I doing wrong?
#mixin box {
background: red;
}
.box {
#if box {
#include box;
} #else {
background: orange;
}
}
The $color: null is just for setting a value if you didn't pass a value for your #mixin. after that you can check easily inside your #mixin using #if #else.
Sass
#mixin background-color($color: null) {
#if($color) {
background-color: $color;
} #else {
background-color: orange;
}
};
h1 {
#include background-color(red);
}
h2 {
#include background-color(green);
}
h3 {
#include background-color();
}
h4{
#include background-color(blue)
}
Html
<h1>color</h1>
<h2>color 2</h2>

Can I achieve this versatile mixin in SASS?

I am attempting to reduce the amount of repitition in the following CSS:
$width_altyp_name : 220px;
$width_view_dates : 140px;
$width_alog_status: 60px;
tr,
td {
line-height: 3;
.view_date_raised,
.view_date_sent {
max-width: $width_view_dates;
min-width: $width_view_dates;
}
.altyp_name {
max-width: $width_altyp_name;
min-width: $width_altyp_name;
}
.alog_ID {
max-width: $width_altyp_name;
min-width: $width_altyp_name;
}
.alog_status_text {
max-width: $width_alog_status;
min-width: $width_alog_status;
}
}
I am wondering whether I can use #mixin (or anything else) to produce a "function" which will take 2 arguments:
$classname
$width
and use that to generate CSS rules in the style of the following:
#mixin set-column-width($classname, $width)
$classname {
max-width: $width;
min-width: $width;
}
}
I would hope to then replace much of the above with something like:
#include set-column-width(".view_date_raised", $width_view_dates);
#include set-column-width(".altyp_name", $width_altyp_name);
#include set-column-width(".alog_status_text", $width_alog_status_text);
Thanks to #Arkellys for pointing out that all I needed to do was understand interpolation
My revised SASS is this:
$width_alog_ID : 60px;
$width_alog_status: 60px;
$width_altyp_name : 220px;
$width_emp_names : 150px;
$width_view_dates : 140px;
#mixin set-column-width($c, $w) {
#{$c} {
max-width: $w;
min-width: $w;
}
}
tr,
td {
line-height: 2;
#include set-column-width('.view_date_raised', $width_view_dates);
#include set-column-width('.view_date_sent', $width_view_dates);
#include set-column-width('.altyp_name', $width_altyp_name);
#include set-column-width('.alog_ID', $width_alog_ID);
#include set-column-width('.alog_status_text', $width_alog_status);
#include set-column-width('.emp_drafter', $width_emp_names);
#include set-column-width('.emp_sender', $width_emp_names);
}

Is there a way to include a mixin as a variable

I just tried to save me some time, generating some helper css classes for different breakpoints.
What I tried:
#mixin resp { width: 100%; height: auto;}
#mixin table { display: table}
#mixin trow { display: table-row}
#mixin tcell { display: table-cell; }
#mixin gutter1px { padding: 0 1px; }
$tools: resp, table, trow, tcell, gutter1px;
#mixin make-tools($breakpoint) {
#each $tool in $tools {
$i: index($tools, $tool);
.#{$tool}-$breakpoint { #include #{$tool}(); }
}
}
#media (min-width: $screen-xs-min) {
#include make-tools(xs);
}
But this dosent seem to work:
#include #{$tool}();
Has anyone an idea how to archive that, or is it simply not possible?

Updating a mixin for themes with SASS 3.4.7

I updated today SASS to use the version 3.4.7 Unfortunetly, one mixin I used since the beginning of my project don't work anymore. I don't understand why...
$program: test1;
#mixin program($programName) {
#each $p in $programName {
#if $p == $program {
#content;
}
}
}
$cta-box-type: null !default;
#include program(test1) {
$cta-box-type: cta-buy, cta-like;
}
#include program(test2) {
$cta-box-type: cta-like, cta-share;
}
#each $cta-type in $cta-box-type {
.banner--#{$cta-type} .banner {
background: white image-url("Modules/Cta/bg-#{$cta-type}-1.jpg") no-repeat bottom left;
background-size: 100% auto;
}
}
DEMO SASSMEISTER
The compiled result looks like this:
.banner-- .banner {
background: white url('/images/Modules/Cta/bg--1.jpg') no-repeat bottom left;
background-size: 100% auto;
}
Instead of:
.banner--cta-buy .banner {
background: white url('/images/Modules/Cta/bg-cta-buy-1.jpg') no-repeat bottom left;
background-size: 100% auto;
}
.banner--cta-like .banner {
background: white url('/images/Modules/Cta/bg-cta-like-1.jpg') no-repeat bottom left;
background-size: 100% auto;
}
If someone have an idea why it's no more working, it's gone help me a lot !
Thanks !
I found the solution :
I simply removed the !default and add !global.
$cta-box-type: null;
#include program(test1) {
$cta-box-type: cta-buy, cta-like !global;
}
#include program(test2) {
$cta-box-type: cta-like, cta-share !global;
}

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');
}
}
}
}

Resources