On Github AhoyLemon / minnebar2016
The best game on the internet
GizmodoIf you tweeted at me during this, that would be fine. Some people find it rude, but I like the attention.
It's called The F Plus. We read terrible things with enthusiasm.
I'm proud of it, but it probably isn't appropriate for your workplace.
Anyway, you can go to thefpl.us for that.
Well, Jade and Sass. We'll skip javascript for now.
It's a way for you, as a developer to write quicker, prettier, more maintainable code, and let the computers do the crappy parts.
.tech-logos { @include flex-container(); @extend %gutters; .logo { @include flex-item(20%,0); } }
.reveal .tech-logos { display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; flex-wrap: wrap; padding-top: 1em; padding-bottom: 1em; } .reveal .tech-logos .logo { width: 20%; -webkit-flex-basis: 20%; -ms-flex-preferred-size: 20%; flex-basis: 20%; -webkit-flex-grow: 0; -ms-flex-positive: 0; flex-grow: 0; -webkit-flex-shrink: 1; -ms-flex-negative: 1; flex-shrink: 1; -webkit-align-self: auto; -ms-flex-item-align: auto; align-self: auto; }
#content .left.column %h2 Welcome to our site! %p= print_information .right.column %label %span Enter your name %input(type=text selected)
#content .left.column h2 Welcome to our site! p= information .right.column label span Enter your name input(type=text selected)
#content .left.column %h2 Welcome to our site! %p= print_information .right.column %label %span Enter your name %input(type=text selected)
#content .left.column h2 Welcome to our site! p= information .right.column label span Enter your name input(type=text selected)
*This statistic from the same place Carly Fiorina gets her facts from.
But here's the logo...
A task runner can do a number of things, but the main use is that when you save a file, it'll process it into a different kind of file.
Now you can write Sass & Jade.
The most immediate change you can make.
.topnav { position:fixed; top:0; right:0; left:0; height:4rem; .inner { padding-left:10px; padding-right:10px; } a { color:white; text-decoration:none; &.big { font-size:1.3em; } &:hover { background:white; color:black; } } }
.topnav { position:fixed; top:0; right:0; left:0; height:4rem; .inner { padding-left:10px; padding-right:10px; } a { color:white; text-decoration:none; &.big { font-size:1.3em; } &:hover { background:white; color:black; } } }
.topnav { position:fixed; top:0; right:0; left:0; height:4rem; } .topnav .inner { padding-left:10px; padding-right:10px; } .topnav a { color:white; text-decoration:none; } .topnav a.big { font-size:1.3em; } .topnav a:hover { background:white; color:black; }
Just change your .css file to .scss, and you're ready to start nesting.
While nesting is useful, it can (like anything programming related) get out of hand.
If you can help it, try to limit your nesting to 4 deep
.because { .this { .is { .not { .how { .you { .should { .write { .code { color:lime; } } } } } } } } }
People get opinionated about this, but you'll be fine.
@import "globals/_variables"; @import "globals/_mixins"; @import "globals/_reset"; @import "sections/_header"; @import "sections/_main"; @import "sections/_footer"; @import "pages/_home"; @import "pages/_error"; @import "pages/_email";
Move stuff around at will, or yank out entire imports and laugh at their demise. The world is yours!
This also prevents stuff like this...
I keep them organized by what the block of code does, with broader ideas sharing a folder together.
That works for me, but you do you.
// FONTS $font-size:14px; $light:300; $bold:700; $slab:'Roboto Slab', serif; // COLORS $white:#f0f1f2; $black:#333; $red:#b22028; // MEASUREMENTS $topnav-height: 4rem; $mobile-max:780px; $desktop-min:781px;
body { font-family:$font; font-size:$font-size; background:$white; color:$black; } h1 { font-weight:$bold; } header { height:$topnav-height; .inner { height:($topnav-height / 2) } } @media screen and (max-width:$mobile-max) { header { display:none; } }
Or z-index:9999999;
Or changing the code a hundred times because the logo needed more padding.
@mixin flex-container($align:stretch, $direction:row, $wrap:wrap) { display: flex; flex-direction: $direction; flex-wrap: $wrap; @if ($align != "stretch") { align-items: $align; } } @mixin flex-item($basis, $grow:1, $shrink:1, $align:auto) { @if $grow == 0 { width:$basis; flex-basis: $basis; } @else { flex-basis: $basis; } flex-grow: $grow; flex-shrink: $shrink; align-self: $align; } @mixin respond-to($media) { @if $media == desktop { @media only screen and (min-width: $desktop-min) { @content; } } @else if $media == mobile { @media only screen and (max-width: $mobile-max) { @content; } } } @mixin flex-split($desktop, $mobile) { @include respond-to(desktop) { @include flex-item($desktop); } @include respond-to(mobile) { @include flex-item($mobile); } }
You can define basic ideas with default values, then alter those values for specific cases.
Which is like, kind of the point of CSS.
%inner { width: 100%; max-width:$max-width; margin-left:auto; margin-right: auto; } %clearfix { &:after { content: ""; display: table; clear: both; } } %quote { &:before { content: '\201C'; } &:after { content: '\201D'; } } header, main, footer { @extend %inner; .float-container { @extend %clearfix; } } blockquote { p { @extend %quote; } }
If you see a design with a lot of the same padding, borders, shadows or hover effects used frequently, throw those in an extend.
This will make it much easier to change if when the designer changes her mind about how they should look.
None of these will end up in your processed CSS until they're actually used, so you can horde them like a dragon.
I have about a dozen Sass partials that I carry over into every new project, so I can keep writing the same code.
Also to prevent myself for looking up the hex code for Facebook Blue for the 100th time.
This is technically not a Sass thing, but you get it.
And you'll like it.
@keyframes sunrise { 0% { bottom: 0; left: 340px; background: #f00; } 33% { bottom: 340px; left: 340px; background: #ffd630; } 66% { bottom: 340px; left: 40px; background: #ffd630; } 100% { bottom: 0; left: 40px; background: #f00; } } .sun { animation: 10s ease infinite; }
@-webkit-keyframes sunrise { 0% { bottom: 0; left: 340px; background: #f00; } 33% { bottom: 340px; left: 340px; background: #ffd630; } 66% { bottom: 340px; left: 40px; background: #ffd630; } 100% { bottom: 0; left: 40px; background: #f00; } } @keyframes sunrise { 0% { bottom: 0; left: 340px; background: #f00; } 33% { bottom: 340px; left: 340px; background: #ffd630; } 66% { bottom: 340px; left: 40px; background: #ffd630; } 100% { bottom: 0; left: 40px; background: #f00; } } .sun { -webkit-animation: 10s ease infinite; animation: 10s ease infinite; }
Writing -ms-flex is for chumps.
HTML was made by smart people, but it is basically immovable.
Any new stuff that's added to HTML has to exist alongside code that was approved in 1999.
Because of this, you end up typing weird things.
<input type="text" disabled="disabled" /> <textarea required="required"></textarea> <h1>Headline</h1> <hr /> <input type="submit" value="Submit" /> <button type="submit">Submit</button>
<div> <div> <div> <div> <div> <div> <div> <div> <script src="SomeStupidTrackingScript.js"></script> </div> </div> </div> </div> </div> </div> </div> </div>Source: Carly Fiorina
.so .whenever .you want to .nest .just hit .tab
<div class="so"> <div class="whenever"> <div class="you">want to <div class="nest"> <div class="just">hit <div class="tab"></div> </div> </div> </div> </div> </div>
h3.jade-headline#JadeHeadline With span.green Jade | , you i only code write the parts span.bigger you b need | to.
<h3 id="JadeHeadline" class="jade-headline"> With <span class="green">Jade</span>, you <i> only </i> <code>write the parts</code> <span class="bigger">you <b>need</b> to. </span> </h3>
- var pageTitle = "Your Lucky Number" - var lastUpdated = "04.20.2016" - var luckyNumber = Math.floor((Math.random() * 100) + 1); head title= pageTitle link(href="css/minnebar.css?updated=#{lastUpdated}) body h1 Your lucky number is span.number= luckyNumber
But unlike Sass, you can use any javascript function you like to create those variables.
Random numbers, conditional iterations, it's madness I tells ya, madness!
doctype html html(lang="en") head include partials/head.jade body include partials/topnav.jade main h1 Welcome to my home page! include partials/footer.jade include partials/javascripts.jade
Global markup is bound to change sometimes. By keeping everything segmented, you can reuse all the parts you'd otherwise have to write more than once.
Unless you need a client-facing CMS, Jade can do most of the stuff you'd otherwise use PHP for.
Build some HTML and host it on GitHub for free.
mixin button(text, url) if url a.active-button= text else .placeholder= text +button("VISIT GOOGLE", 'http://google.com') +button('This is not a button')
I know I said this earlier, but unfettered javascript accesss makes mixins even better.
mixin placeholder(caption, height, width) - var tinaQuotes = ["Everyone touch each other's butts", "My heart!", "I put my bra on one boob at a time like everyone else.", "Dad, I need you to drop everything and shave my legs"] if !caption - caption = tinaQuotes[n] if !height - height = 600 if !width - width = Math.floor((Math.random() * 600) + 500); figure img(src="https://unsplash.it/#{width}/#{height}") figcaption= caption n++ +placeholder("Hi boys, I'm Tina.",400,850) +placeholder("If boys had uteruses they’d be called duderuses") +placeholder()
- var testamonials = [ {text: "This Sass & Jade presentation is the Crank: High Voltage of tech talks!", cite: "Jason Statham" }, {text: "Lemon just made me like a million times smarter", cite: "Neil DeGrasse Tyson" }, {text: "I heard this whole presentation is a terrorist conspiracy", cite: "Carly Fiorina" }, {text: "Butts.", cite: "Tina Belcher" } ] each quote in testamonials blockquote p= quote.text cite= quote.cite
This Sass & Jade presentation is the Crank: High Voltage of tech talks!
Jason StathamLemon just made me like a million times smarter
Neil DeGrasse TysonI heard this whole presentation is a terrorist conspiracy
Carly FiorinaButts.
Tina BelcherAnd with both of these languages, I had times where I wished I was writing code the old way.
But when you get good at this stuff, you improve your workflow.
You write better, you write quicker, and you get the knowledge of knowing a new thing.
This slidedeck was written in Jade, Sass, and Reveal.js
Available online at ahoylemon.github.io/minnebar2016