Unit 6, Week 7
Object-oriented CSS, SCSS/Compass
A way of describing reality in code, with a range of patterns, and a way of thinking about program entities regardless of the programming languages being used.
We can talk about "things", not code. Our things interact with other things.
MindBEMding: CSSWizardry
BEM Methodology: Smashing
<ul class="menu menu--big menu-inline">...</ul> // .menu--big{ // big menu code here } .menu--small{ // small menu code here }
Still produces good ol' CSS.
$ gem install compass
Now navigate to the folder of one of the local urls we've created recently. For instance, the folder for my wdim351.com is
/Applications/MAMP/htdocs/dev/wdim351
Set up a new SASS/Compass project:
$ compass create <myproject>
Add an index.html to that folder and include the screen.css file:
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
$ compass watch
Let's edit /sass/screen.scss:
.thing1{
.thing2{
.thing3{
background: blue;
}
}
}
BOOM, now check /css/screen.css:
...
/* line 10, ../sass/screen.scss */
.thing1 .thing2 .thing3 {
background: blue;
}
Everything from here out straight from sass-lang.com
#navbar {
width: 80%;
height: 23px;
ul { list-style-type: none; }
li {
float: left;
a { font-weight: bold; }
}
}
Becomes
#navbar {
width: 80%;
height: 23px;
}
#navbar ul {
list-style-type: none;
}
#navbar li {
float: left;
}
#navbar li a {
font-weight: bold;
}
#header .nav .top .menu-top.inline ul li a{ //properties }
That's the result of:
#header{
.nav{
.top{
.menu-top{
&.inline{
ul{
li{
a{ // properties }
}
}
}
}
}
}
}
It's easy to get carried away with nesting. Don't follow document tree. Follow OOCSS.
.fakeshadow {
border: {
style: solid;
left: {
width: 4px;
color: #888;
}
right: {
width: 2px;
color: #ccc;
}
}
}
.fakeshadow { border-style: solid; border-left-width: 4px; border-left-color: #888; border-right-width: 2px; border-right-color: #ccc; }
a {
color: #ce4dd6;
&:hover { color: #ffb3ff; }
&:visited { color: #c458cb; }
}
Becomes
a {
color: #ce4dd6;
}
a:hover {
color: #ffb3ff;
}
a:visited {
color: #c458cb;
}
$main-color: #ce4dd6;
$style: solid;
#navbar {
border-bottom: {
color: $main-color;
style: $style;
}
}
a {
color: $main-color;
&:hover { border-bottom: $style 1px; }
}
#navbar {
border-bottom-color: #ce4dd6;
border-bottom-style: solid;
}
a {
color: #ce4dd6;
}
a:hover {
border-bottom: solid 1px;
}
#navbar { $navbar-width: 800px; $items: 5; $navbar-color: #ce4dd6; width: $navbar-width; border: 2px solid $navbar-color; li { float: left; width: $navbar-width/$items - 10px; background-color: lighten($navbar-color, 20%); &:hover { background-color: lighten($navbar-color, 10%); } } }
#navbar { width: 800px; border-bottom: 2px solid #ce4dd6; } #navbar li { float: left; width: 150px; background-color: #e5a0e9; } #navbar li:hover { background-color: #d976e0; }
@mixin rounded($vert, $horz, $radius: 10px) { border-#{$vert}-#{$horz}-radius: $radius; -moz-border-radius-#{$vert}#{$horz}: $radius; -webkit-border-#{$vert}-#{$horz}-radius: $radius; } #navbar li { @include rounded(top, left); } #footer { @include rounded(top, left, 5px); } #sidebar { @include rounded(top, left, 8px); }
#navbar li { border-top-left-radius: 10px; -moz-border-radius-topleft: 10px; -webkit-border-top-left-radius: 10px; } #footer { border-top-left-radius: 5px; -moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; } #sidebar { border-top-left-radius: 8px; -moz-border-radius-topleft: 8px; -webkit-border-top-left-radius: 8px; }