Sass Never Forgets
Posted: July 9th, 2009 | Author: Jerod | Filed under: Ruby | Tags: css, mixins, sass | View CommentsSome CSS techniques require me to Google about like a chicken with its head cut off. One such technique is placing a div in the dead center of a page (vertically and horizontally). Since I’m using Sass pretty much exclusively these days, I decided to define this technique as a mixin so I don’t have to look it up anymore.
Hopefully this can be of use to others. YMMV:
The mixin definition:
=dead-center(!height,!width) :height= !height :margin-top= -(!height / 2) :top 50% :width= !width :margin-left= -(!width / 2) :left 50% :position absolute :text-align center
To use it on an element:
#centered +dead-center(200px,500px)
Now I’ll never forget how. Thanks Sass!
[...] Sass Never Forgets | blogt0sk1 [...]
Thanks for sharing Jerod… very handy! Just added your mixin to my application.sass
I've been using the typical mixin for rounded corners as well as these for when i only want rounded corners on the top or bottom of an element:
=border-radius-top-LR(!rad = 4px)
:-moz-border-radius-topleft = !rad
:-moz-border-radius-topright = !rad
:-webkit-border-top-left-radius = !rad
:-webkit-border-top-right-radius = !rad
:border-top-left-radius = !rad
:border-top-right-radius = !rad
=border-radius-bottom-LR(!rad = 4px)
:-moz-border-radius-bottomleft = !rad
:-moz-border-radius-bottomright = !rad
:-webkit-border-bottom-left-radius = !rad
:-webkit-border-bottom-right-radius = !rad
:border-bottom-right-radius = !rad
:border-bottom-left-radius = !rad
Thanks Paul, I'll add these to my mixin collection!
Thanks Paul, I'll add these to my mixin collection!
[...] Sass Never Forgets – dead-center mixin A sass mixin for centering a div vertically and horizontally. I can never remember this technique either Jerod. [...]