A little diversion from last week:
What is code?
p {
color: beige;
}
(yes, CSS has more then 16 colors, use them)
Rules, selectors, properties.
And you are (almost) good to go!
/* Element */
h1 {}
/* Class */
.isolated {}
/* Identifier */
#products {}
There's more, much more, but stick with that, for the moment.
/*
* Composition allows to take advantage of
* the HTML hierarchies (section and header
* are HTML5 elements).
*/
.main-column section header h1 {}
<header id="excerpt" class="important">
<h1>I'm the title of the excerpt</h1>
</header>
/*
* Who wins?
*/
h1 { color: slategrey; }
header h1 { color: bisque; }
.important h1 { color: lavender; }
#excerpt h1 { color: chocolate; }
Specificity calculator and specificity hack may be useful.
.media {}
.media .img {}
.media .img img {}
.bd {}
/* Base rules */
html, body, form {
margin: 0; padding: 0;
}
input[type=text] {
border: 1px solid #999;
}
a {
color: #039;
}
/* Layout rules */
#header, #article, #footer {
width: 960px;
margin: auto;
}
#article {
border: solid #CCC;
border-width: 1px 0 0;
}
/* Module rules */
.module > h2 {
padding: 5px;
}
.module span {
padding: 5px;
}
/* State rules */
.is-tab-active {
background-color: white;
color: black;
}
.media {}
.media__img {}
.media__img img {}
.media__bd {}
.media--reverse {}
(and do all this stuff respecting a strict convention on class names)
That's fine, but… what if you decide to use a front-end framework based on classes too? Like, let's say:
<div class="row">
<div class="col-md-8 col-main">
<p class="text-lowercase">A</p>
</div>
<div class="col-md-4">
<p class="text-lowercase">B</p>
</div>
</div>
<div class="row">
<div class="col-md-8">Entry level</div>
<div class="col-md-4">1234</div>
</div>
Bourbon plus Neat plus SASS or Less
In HTML:
<section>
<aside>What is it about?</aside>
<article>Semantic grid framework...</article>
</section>
And in CSS:
section {
@include outer-container;
aside { @include span-columns(3); }
article { @include span-columns(9); }
}
Attribute Modules (AM) is a technique for using HTML attributes and their values rather than classes for styling elements.
In doing so, each attribute effectively declares a separate namespace for encapsulating style information, resulting in more readable and maintainable HTML & CSS.
/* From: */
<a class="btn btn-primary btn-lg">Click me!</a>
/* To: */
<a am-Button="primary large">Click me!</a>
/* Or: */
<a data-am-Button="primary large">Click me!</a>
/* In CSS: */
[am-Button] {}
[am-Button~="primary"] {}
[am-Button~="large"] {}