Background
I really wanted to learn how to use Grunt and to refresh my languishing Sass knowledge,
and I needed to update my personal domain anyway.
Thus, this tiny page was born.
Grunt
I went through a few tutorials to get a feel for things, and ended up using these packages:
- Watch: Monitors changes in my directory and takes actions as set in GruntFile.js
- Uglify: I ended up not writing any JavaScript for this bitty page, but if I had, Uglify would
minify it
- Sass: Compiles the .scss files into .css
- Matchdep: Dynamically loads other packages in GruntFile.js, so I don't have to add them all manually
I set up the default task to run Sass:dev and Watch, and I set a "deploy" task to run Sass:deploy and Uglify,
which minified files into my deployment folder.
Some other packages I'd like to try:
- Imagemin: Compresses image files
- LiveReload: Automatically refreshes the browser on changes; requires a browser extension
- UnCSS: Removes unused CSS from the project; seems especially useful when using Bootstrap or another framework
- CSSmin and HTMLmin: Minifies CSS and HTML
- Compass: How is this different from the Sass package, other than requiring a config.rb file? I am unclear.
A few helpful Grunt resources:
Sass
I had used Sass over a year ago, so while rusty, I was somewhat familiar. I kept the
Sass Documentation handy and referenced
my previous project, which included partials, variables, nesting, import, and built-in
functions like darken
.
In future projects, I plan on exploring @extend
and @mixin
. I'm also very interested
in Control Directives and SassScript.
Snippets
Imports & Partials
To keep my files a bit tidier, I used the _filename.scss
scheme to keep those files from being converted
to separate CSS files. Instead, I imported them into my main styles.scss
file, so that they would be converted together.
I first imported the normalize.css
reset that had been coverted to .scss by
kristerkari, and made a _global.scss
file to hold all my variables and general styling.
Box Hover Styles
I wanted some visual interest on this simple page, so on hover, the boxes have some subtle changes.
I wanted to make things very easy to click, so each image is a link. On hover, a few things happen:
- The subtley transparent image becomes fully opaque
- The box translates up slightly
- The shadow grows and darkens so that the background is visually stationary as the box appears to lift
I also like the trick of a negative box-shadow
size to keep the shadow centered underneath.
Responsive Design
I wanted to try out flexbox
, so I used that in combination with a media query to achieve a readable,
responsive layout.
On smaller screens, the boxes stack vertically and stretch to fill the screen with flex-flow: column
and align-items: stretch
. On large screens, they group into a square by setting the min-width
and flex-flow: row wrap
.
The background-size: cover
was a super easy fix to allow for my boxes to change shape and still keep full
coverage with the image. Unfortunately
it didn't work properly when I refactored that style away from its background declaration (separate, as each box
has a different image), so my code isn't quite as DRY as I might like.
I added a gradient as a second background on top of the image, so that the text would be more readable.
I originally was looking at a pseudo-element with a transparent background to tint the image, but it tinted the text
as well. It would have made setting a hover state tint easier, but alas.