On Github richard-tirta / get-away-css
<table> <tr> <td align="left" onClick="donothing()"> <center> <font face="verdana"> <b> <p> Hello World </p> </b> </font> </center> </td> </tr> </table>Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you open the speaker notes window (hit 's' on your keyboard).
CSS2
p { font-size: 30px; // we set global font size here @media all and (max-height: 768px){ // now we have media query font-size: 20px; } } #section-1 { p { font-size: 20px; // apparently section-1 needs to be specific @media all and (max-height: 568px){ // and so their media query font-size: 10px; } .callout-p { font-size: 15px; // section 1 callout is specific too @media all and (max-height: 568px){ font-size: 20px; } .description { font-size: 12px; @media all and (max-height: 568px){ font-size: 10px; } } } } }
block, element, modifier
Scalable and Modular Architecture for CSS
Object oriented CSS
I'm not ( yet ) a CSS Evangelist/ Architect.
We discuss this as a style guide and standard practice techniques.
We will be strictly speaking about solutions within CSS.
BEM, SMACSS & OOCSS are not rivals.
No production exp, hoping we can standarized.
Some frameworks around.
Angular directives or Shadow DOM using Web Components.
They have competing arguments and abstractions, and thus this isn’t about benchmarking them. Different ideas can be mixed and match or cherry picked
BEM – meaning block, element, modifier – is a front-end naming methodology.
It is a smart way of naming your CSS classes to give them more transparency and meaning to other developers.
.block {} /*higher level of an abstraction or component */ .block__element {} /*descendent of block, usually would be .block .element */ .block--modifier {} /*different state version of block, usually would be .block.modifier */ /* module overview */ .module-overview {}
Hypen and Underscores?
/* paragraph descendant inside module overview */ .module-overview__p {} /* module overview with current state*/ .module-overview--current {} /* paragraph descendant inside module overview in which the paragraph is in current state*/ .module-overview__p--current {}We make DOUBLE hypen and underscores so it can be chained.
HTML with regular CSS
<section class="module-overview current"><!-- the current class can have hidden properties --> <p>Content 1</p> <div class="content"><!-- this content class is very general and easy to confuse --> <p class="current">Content 2</p> </div> </section>
BEM
<section class="module-overview module-overview--current"> <p class="module-overview__p">Content 1</p> <div class="module-overview__content"> <p class="content__p--current">Content 2</p> </div> </section>
current class can have hidden properties not for module-overview
It looks ugly.
And if you overdo it
.module-1--show-content{ min-height: 280px; transform: translatey(0); } .module-1__languageDropdown{ @include clearfix; pointer-events: auto; position: absolute; top: 0; right: 0; z-index: 9; } .module-1__content { padding-top: 1px; position: relative; pointer-events: none; width: 100%; margin: 0 auto; transition: opacity 1s; z-index: 5; } .module-1__content--hide-content { opacity: 0; } .module-1__content__logo { margin: 0 auto 5px auto; }
It can get really ugly
.module-1__content__headline-container { position: relative; } .module-1__content__headline-container__headline { width: 100%; overflow: hidden; transition: opacity 1s; text-align: center; } .module-1__content__headline-container__headline__main-headline { display: block; } .module-1__content__headline-container__headline__alt-headline { display: none; } .module-1__content__headline-container__headline--show-headline__headline-0 { opacity: 1; height: auto; } .module-1__content__headline-container__headline--show-headline__headline-1 { opacity: 0; height: 0; } .module-1__content__headline-container__headline--show-headline__headline-2 { opacity: 0; height: 0; } .module-1__content__headline-container__headline--show-headline__headline-3 { opacity: 0; height: 0; }
For starter, take it with a grain of salt and don't overdo it
// Embrace SASS .module-1 { .show-headline__headline-3 { opacity: 0; height: 0; } }
You will start liking it.
Scalable and Modular Architecture for CSS.
It's a simple set of rules that guide you in laying out your CSS.
5 Main Categories
Are basically, base styles.
html, body, form { margin: 0; padding: 0; } a { color: black; }
Major components
#header, #article, #footer { width: 960px; margin: auto; } #article { border: solid #CCC; border-width: 1px 0 0; } .section { display: block; position: relative; width: 100%; }
Re-usable minor components
.callouts { background: rgb(100,100,100); color: white; display: block; width: 300px; height: 300px; } .product { width: 100%; height: 100px; } .module > h2 { padding: 5px; } .module span { padding: 5px; }
State that overrides default styles
.hide { opacity: 0; } .show { opacity: 1; } .tab { background-color: purple; color: white; } .is-tab-active { background-color: white; color: black; }
Generally you won't use theme
But it's useful when you have multiple theme, typography and localization.
More details about CSS good practices: https://smacss.com/
SMACSS is about a guide and there're more details that can't be covered.Object oriented CSS (OOCSS) is a methodology of writing reusable CSS that is fast, modular, scalable and maintainable.
This is where we make objects (in this case HTML elements), modular and location independent, able to be placed anywhere on a page and behave predictably.
NOT DRY
#button { width: 200px; height: 50px; padding: 10px; border: solid 1px #ccc; /*NOT DRY*/ background: linear-gradient(#ccc, #222); /*NOT DRY*/ box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; /*NOT DRY*/ } #box { width: 400px; overflow: hidden; border: solid 1px #ccc; /*NOT DRY*/ background: linear-gradient(#ccc, #222); /*NOT DRY*/ box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; /*NOT DRY*/ }
with OOCSS
.button { width: 200px; height: 50px; } .box { width: 400px; overflow: hidden; } .skin { border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; }
Even better with SASS
@mixin skin { border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } .button { @include skin; width: 200px; height: 50px; } .box { @include skin; width: 400px; overflow: hidden; }
docssa.info