SlideShare una empresa de Scribd logo
1 de 21
CSS architecture and methodology
Presentation by Lasha sumbadze
itCSS
• ITCSS – ‘Inverted Triangle CSS' is a new methodology. It involves visualising your entire CSS
project as a layered, upside-down triangle. This hierarchical shape represents a model that will help
you order your CSS in the most effective, least wasteful way.
• gives us far better scalability and maintainability
• Generic to explicit
We start out with the most generic, low-level, catch-all, unremarkable styles, and eventually progress to more
explicit and specific rules as we move through the project. We might start with our reset, then progress to slightly
more scoped rules like h1–6 {} , right through to extremely explicit rules such as .text-center {} .
Read more at http://technotif.com/manage-large-css-projects-with-itcss/#qKXhAprDAHwLVGpw.99
• Low specificity to high specificity
The lowest-specificity selectors appear towards the beginning, with specificity steadily increasing as we progress
through the project. We want to ensure that we avoid as much of the Specificity Wars as we can, so we try and
refrain from writing higher-specificity selectors before lower-specificity ones. We’re always adding specificity in
the same direction, thus avoiding conflicts.
• Far-reaching to localised
Selectors towards the beginning of the project affect a lot of the DOM, with that reach being progressively
lessened as we go through the codebase. We want to make ‘passes’ over the DOM by writing rules that affect
progressively less and less of it. We might start by wiping the margins and paddings off everything, then we might
style every type of element, then narrow that down to every type of element with a certain class applied to it, and
so on. It is this gradual narrowing of reach that gives us the triangle shape. Ordering our projects according to
these key metrics has several benefits. We can begin to share global and far-reaching styles much more effectively
and efficiently, we vastly reduce the likelihood of specificity issues, and we write CSS in a logical and progressive
order. This means greater extensibility and less redundancy, which in turn means less waste and much smaller file
sizes.
• Settings
If you are using a preprocessor, start here. This holds any global settings for your project. Settings like $heading-size-1 should
be defined all variables that holds values that uses
• Tools
mixins and functions. Any mixin or function that does not need accessing globally should belong in the partial to which it
relates.Examples of global tools might be gradient mixins, font-sizing mixins and so on.
• Generic
high-level, far reaching styles. This layer is seldom modified,It contains things like Normalize. css, global box-sizing rules,
CSS resets and so on.
• Elements
Elements layer binds onto bare HTML element (or ‘type’) selectors only. It is slightly more explicit than the previous layer in
that we are now saying ‘make every h1 this big’ , or ‘make every a be a certain colour’.
• Objects
Users of OOCSS will be familiar with the concept of objects. This is the first layer in which we find class-based selectors.
These are concerned with styling non-cosmetic design patterns, or ‘objects’. Objects can range from something as simple as
a .wrapper element, to layout systems
• Components
The Components layer is where we begin to style recognisable pieces of UI. We’re still binding onto classes here, so our
specificity hasn’t yet increased. However, this layer is more explicit than the last one in that we are now styling explicit,
designed pieces of the DOM.
• Trumps
This layer beats – or ‘trumps’ – all other layers, and has the power to override anything at all that has gone before it. It is
inelegant and heavyhanded, and contains utility and helper classes, hacks and overrides. A lot of the declarations in this layer
will carry !important (e.g. .text-center { text-align: centre !important; } ). This is the highest specificity layer
• @import “settings.global”;
@import “settings.colors”;
• @import “tools.functions”;
@import “tools.mixins”;
• @import “generic.box-sizing”;
@import “generic.normalize”;
• @import “elements.headings”;
@import “elements.links”;
• @import “objects.wrappers”;
@import “objects.grid”;
• @import “components.site-nav”;
@import “components.buttons”;
@import “components.carousel”;
• @import “trumps.clearfix”;
@import “trumps.utilities”;
@import “trumps.ie8”;
Object oriented css
• Object-oriented CSS, at its core, is simply writing cleaner, DRYer CSS.
It’s just a paradigm shift. The purpose of OOCSS is to encourage code reuse and, ultimately, faster and
more efficient stylesheets that are easier to add to and maintain
• OOCSS is based on two main principles:
The first is to separate the structure from the skin :
Layout and design styling are separate .In other words separation Colors, borders and other visual characteristics
from styling background, color, animation ,border, etc. this means not to mix structure/positioning properties with
skin/styling properties on the same class.
The bad way The good way
.button-1 {
border: 1px solid #ccc;
width: 50px;
height: 50px;
border-radius: 5px;
}
.button-2 {
border: 1px solid #ccc;
width: 70px;
height: 20px ;
border-radius: 5px;
}
button-1 {
width: 50px;
height: 50px;
}
.button-2 {
width: 70px;
height: 20px ;
}
.button-border {
border: 1px solid #ccc;
border-radius: 5px;
}
The second is to separate the container from the content:
Break the dependency between the container module and the content objects it contains separating container from
content,A styled element should never be dependent on where it’s at in a page
Essentially, this means “rarely use location-dependent styles”.
<input> with .call_info form .left_call_info input <input> , like <input class=“input_pos input_skin">.
The bad way The good way
.call_info form .left_call_info input {
border: none;
width: 400px;
height: 30px;
background-color: #e9e9e9;
color: #122c49;
padding-left: 5px;
font-size: 10px;
}
.input_pos {
width: 400px;
height: 30px;
padding-left: 5px;
}
.input_skin {
background-color: #e9e9e9;
color: #122c49;
font-size: 10px;
}
What about semantic css?
• You shouldn't care about being non-semantic
The only way to make objects in plain CSS is to define non-semantic classes. However, this comes with
some problems:
• DOM will be overloaded.
<a href="#" id=“click_it” class="btn border box-shadow btn-small btn-blue nice clickable">Click me!</a>
• There's not a safe way to access some of the DOM elements. there is no best way so you have to
choose what is good for particular case .
document.getElementsByClassName(“clickable ”);
x[0].innerHTML = "Hello World!";
Or
document.getElementById(“click_it”);
x.innerHTML = "Hello World!";
Or
document.querySelectorAll(“.clickable ”);
x[0].innerHTML = "Hello World!";
Reusable CSS
• OOCSSS encourage to avoid location dependent styles , you create smaller modules on the page
and extend them with subclasses as necessary
• Reusability is also improved because of the OOCSS encourages abstracting CSS structural styles
and skin level styles.
OOCSS & CSS Preprocessors
• OOCSS and CSS preprocessors solve different problems
• Object oriented CSS is an approach and methodology to achieve the goal while a
preprocessor is a tool to support and enlarge the system.
DRY CSS
• OOCSS focused specifically on abstracting snippets of code, Dry Css focuses primarily on not
repeating yourself..
• The core recommendation of Dry Css is to group reusable properties, name them and then add all
selectors to the group..
• Avoid specificity by harnessing the cascade
• Compared with the OOCSS framework, DRY CSS argues that semantic HTML should be HTML
that reflects the content.
• If the HTML is out of your control, it is obviously valuable, on the other hand it doesn’t
necessarily encourage thoughtful HTML structuring.
“Less” comes into play
The extend directive allows us to easily share styles between selectors.
The bad way The good way
a.twitter {
min-width: 100px;
padding: 1em;
border-radius: 1em;
background: #55acee color: #fff;
}
span.facebook {
min-width: 100px;
padding: 1em;
border-radius: 1em;
background: #3b5998;
color: #fff;
}
.button {
min-width: 100px;
padding: 1em;
}
.button-skin {
border-radius: 1em;
color: #fff;
}
.twitter-background {
background: #55acee;
}
.facebook-background {
background: #3b5998;
}
.btn {
&--twitter {
&:extend(.button);
&:extend(.twitter-background);
&:extend(.button-skin);
}
&--facebook {
&:extend(.button);
&:extend(.facebook-background);
&:extend(.button-skin);
}
}
Classes
• According to most OOCSS methodologies, subclassing is always handled at the HTML level. It’s better to
avoid attaching not more than 3-4 classes to a single element. When attaching a new class we have to
increase semantic value as well as it necessary or it’s better to mix oocss with dry css.
Compiled css Html Comparison
.button,
.btn--twitter,
.btn--facebook {
min-width: 100px;
padding: 1em;
}
.button-skin,
.btn--twitter,
.btn--facebook {
border-radius: 1em;
color: #fff;
}
.twitter-background,
.btn--twitter {
background: #55acee;
}
.facebook-background,
.btn--facebook {
background: #3b5998;
}
<!-- css way -->
<a href="#" class="twitter">Twitter</a>
<a href="#" class="facebook">Facebook</a>
<!– pure oocss way -->
<a href="#" class="button-skin button btn--twitter
">Twitter</a>
<a href="#" class="button-skin button btn--facebook
">Facebook</a>
<!-- dry oocss way with less -->
<a href="#" class=“btn--facebook">Twitter</a>
<a href="#" class=“btn--twitter">Facebook</a>
Mixins and OOCSS
• With preprocessors, we can define so-called "mixins", which have some similarities to functions in
programming languages. In
I suggest you to don’t include mixin when you don’t give it arguments , you can just use extend and
take dry css as we mentioned in past slides or you can just attach it in your html because dry
preprocessor code does not mean dry css code when we compile our code to css we will end up with
repetitions of various properties.
.round(@radius: 5px) {
/* Safari 3-4, iOS 1-3.2, Android 1.6- */
-webkit-border-radius: @radius;
/* Firefox 1-3.6 */
-moz-border-radius: @radius;
/* Opera 10.5, IE 9, Safari 5, Chrome, Firefox 4, iOS 4, Android 2.1+ */
border-radius: @radius;
}
.form-info {
background-color: #ccc;
border: 2px solid rgba(0,0,0,0.7);
.round( 15px) ;
}
Some suggestions to avoid specificity
• Avoid to use IDs in CSS, (anything you can do with an ID, you can do with a class), ID or just selecte it with just
attribute selector [id = “some_id”]
• Do not nest selectors unnecessarily.
• Do not qualify selectors unless you have a compelling reason to do so. If.nav {} will work, do not use ul.nav {};
to do so would not only limit the places you can use the .
• Make heavy use of classes because they are the ideal selector: low specifity great portability, and high reusability.
• Safely increasing specificity .btn.btn { } …will select based on only one class (.btn) but with double the
specificity. We can take this as far as we need to:.btn.btn.btn.btn { }it just asks the same question n times.
• Never use !importantant !important declarations should not be used unless they are absolutely
necessary after all other avenues have been exhausted. It ruins the order
• Descending order of specificity
1. Inline styles
2. ID selectors – (#big)
3. Pseudo Classes (:hover), (:visited) etc.
4. Attributes Selectors – ([href=“”] , [target=“”]);
5. Class Selectors – (.clases)
6. Type Selectors (em, h1, p, ul, li)
7. Universal selectors – (*)
Choose wisely from the toolkit: mixins, extends, a new module or
subclass
Mixins, extends and classes are tools that allow the reduction of repetition in the the act of writing
CSS. Each of these however results in a very different outcome in the final compiled CSS and each
comes with a potential pitfall. Overuse of mixins results in highly repetetive and bloated CSS,
overuse of classes will start to feel like classitis, and an overuse of extends can result in too many
selectors attatched to the same CSS rule.
It’s important to find a good balance and have a process for deciding which solution to use.
Avoid deep-nested selectors and selectors tightly coupled to HTML
• At first , when I started to use preprocessors I was very impressed about that I could write nested
css styles and it was repeating the structure of the DOM , but my impression died when first I’ve
compiled
• So then I realized that to much nesting styles gives you unnecessary specificity and css
downloading time is growing as the size of it, so then I found that there is some kind of
theoretical border for nesting levels : “Note that objects should have at most 4 levels. Most of the
time you'll stay around the 2-3 level range, and the fourth would be the interaction state.”
http://thesassway.com/beginner/the-inception-rule
• I prefer to use not more then 2 levels but there is always some cases when I really need but I am
trying to keep in mind “don’t nested more then 4 levels”
preprocessor code compiled
.container {
.menu-list {
ul {
list-style: none;
li {
padding-left: 10px;
span {
background-image: url() 0 0 no-repeat;
}
}
}
}
}
.container .menu-list ul {
list-style: none;
}
.container .menu-list ul li {
padding-left: 10px;
}
.container .menu-list ul li span {
background-image: url() 0 0 no-repeat;
}
Conclusion• Ultimately, the key to successfully using OOCSS and preprocessors together is understanding the problems that
OOCSS and preprocessors solve as well as the way the final CSS will compile. While CSS preprocessors offer a
number of conveniences to front-end developers, they don’t guarantee efficient, maintainable and scalable code.
By creating a clear folder/file structure, maintaining consistent naming conventions, avoiding deep-nested
selectors or CSS/HTML coupling, and choosing wisely from the toolkit, it is possible to benefit from both OOCSS
and preprocessors.
• OOCSS sources:
• https://github.com/stubbornella/oocss
• http://www.slideshare.net/stubbornella/object-oriented-css?qid=311faf43-46d6-4441-88b0-
b07dc8e3d8ab&v=qf1&b=&from_search=1
• http://appendto.com/2014/04/oocss/
• http://www.smashingmagazine.com/2011/12/an-introduction-to-object-oriented-css-oocss/
• http://cwebbdesign.tumblr.com/post/23666803241/scalable-and-maintainable-css-approaches
• OCSS and preprocessor sources:
• http://thesassway.com/intermediate/using-object-oriented-css-with-sass
• http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/
• https://css-tricks.com/the-extend-concept/
• http://thesassway.com/intermediate/avoid-nested-selectors-for-more-modular-css
• http://thesassway.com/beginner/the-inception-rule
• http://alancrissey.com/articles/more-object-oriented-css-with-less/
• http://blog.mediumequalsmessage.com/guidelines-using-oocss-and-css-preprocessors
Css methods architecture

Más contenido relacionado

La actualidad más candente (9)

Web standards pragmatism - from validation to the real world / Web Developers...
Web standards pragmatism - from validation to the real world / Web Developers...Web standards pragmatism - from validation to the real world / Web Developers...
Web standards pragmatism - from validation to the real world / Web Developers...
 
Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS Properties
 
css-tutorial
css-tutorialcss-tutorial
css-tutorial
 
Html frames
Html framesHtml frames
Html frames
 
Pemrograman Web 4 - Bootstrap 3
Pemrograman Web 4 - Bootstrap 3Pemrograman Web 4 - Bootstrap 3
Pemrograman Web 4 - Bootstrap 3
 
Css tips & tricks
Css tips & tricksCss tips & tricks
Css tips & tricks
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Css3
Css3Css3
Css3
 
CSS Reset
CSS ResetCSS Reset
CSS Reset
 

Destacado

1.9.16RichardsonRebeccaResumeOnly.doc (1)
1.9.16RichardsonRebeccaResumeOnly.doc (1)1.9.16RichardsonRebeccaResumeOnly.doc (1)
1.9.16RichardsonRebeccaResumeOnly.doc (1)
Rebecca Richardson
 
smhcertificate GxP
smhcertificate GxPsmhcertificate GxP
smhcertificate GxP
Addie Bardin
 
Institucional proofpoint
Institucional proofpointInstitucional proofpoint
Institucional proofpoint
voliverio
 

Destacado (18)

Google earth assignment
Google earth assignmentGoogle earth assignment
Google earth assignment
 
Tutorial gabitos
Tutorial gabitosTutorial gabitos
Tutorial gabitos
 
1.9.16RichardsonRebeccaResumeOnly.doc (1)
1.9.16RichardsonRebeccaResumeOnly.doc (1)1.9.16RichardsonRebeccaResumeOnly.doc (1)
1.9.16RichardsonRebeccaResumeOnly.doc (1)
 
Stressed Syllable
Stressed SyllableStressed Syllable
Stressed Syllable
 
smhcertificate GxP
smhcertificate GxPsmhcertificate GxP
smhcertificate GxP
 
PhpStorm
PhpStormPhpStorm
PhpStorm
 
Soil lab (Aggregates Testing)
Soil  lab (Aggregates Testing)Soil  lab (Aggregates Testing)
Soil lab (Aggregates Testing)
 
Pulses in integrated crop systems and agricultural landscapes - Robin Burucha...
Pulses in integrated crop systems and agricultural landscapes - Robin Burucha...Pulses in integrated crop systems and agricultural landscapes - Robin Burucha...
Pulses in integrated crop systems and agricultural landscapes - Robin Burucha...
 
Dafra - Citycom 300i - Manual de Serviço PTBR
Dafra - Citycom 300i - Manual de Serviço PTBRDafra - Citycom 300i - Manual de Serviço PTBR
Dafra - Citycom 300i - Manual de Serviço PTBR
 
Sangamner MDA Activity
Sangamner MDA ActivitySangamner MDA Activity
Sangamner MDA Activity
 
circles
circlescircles
circles
 
Institucional proofpoint
Institucional proofpointInstitucional proofpoint
Institucional proofpoint
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Rda authority records 26.07.2016
Rda authority records 26.07.2016Rda authority records 26.07.2016
Rda authority records 26.07.2016
 
هرم ماسلو
هرم ماسلوهرم ماسلو
هرم ماسلو
 
DoubleClick for Publishers (DFP) Basic Guide
DoubleClick for Publishers (DFP) Basic GuideDoubleClick for Publishers (DFP) Basic Guide
DoubleClick for Publishers (DFP) Basic Guide
 
My Graphic Design Portfolio
My Graphic Design PortfolioMy Graphic Design Portfolio
My Graphic Design Portfolio
 
الألعاب التعليمية
الألعاب التعليميةالألعاب التعليمية
الألعاب التعليمية
 

Similar a Css methods architecture

Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
Peter Kaizer
 

Similar a Css methods architecture (20)

CSS workshop @ OutSystems
CSS workshop @ OutSystemsCSS workshop @ OutSystems
CSS workshop @ OutSystems
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Spectrum 2015 going online with style - an intro to css
Spectrum 2015   going online with style - an intro to cssSpectrum 2015   going online with style - an intro to css
Spectrum 2015 going online with style - an intro to css
 
Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
 
Advance Css
Advance CssAdvance Css
Advance Css
 
Advance Css 1194323118268797 5
Advance Css 1194323118268797 5Advance Css 1194323118268797 5
Advance Css 1194323118268797 5
 
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP ConferenceThe New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
 
Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
Responsive Design in Drupal with Zen and Zen Grids
Responsive Design in Drupal with Zen and Zen GridsResponsive Design in Drupal with Zen and Zen Grids
Responsive Design in Drupal with Zen and Zen Grids
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
 
slides-students-C04.pdf
slides-students-C04.pdfslides-students-C04.pdf
slides-students-C04.pdf
 
CSS3 basics for beginners - Imrokraft
CSS3 basics for beginners - ImrokraftCSS3 basics for beginners - Imrokraft
CSS3 basics for beginners - Imrokraft
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Pemrograman Web 2 - CSS
Pemrograman Web 2 - CSSPemrograman Web 2 - CSS
Pemrograman Web 2 - CSS
 

Último

Último (20)

KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 

Css methods architecture

  • 1. CSS architecture and methodology Presentation by Lasha sumbadze
  • 2. itCSS • ITCSS – ‘Inverted Triangle CSS' is a new methodology. It involves visualising your entire CSS project as a layered, upside-down triangle. This hierarchical shape represents a model that will help you order your CSS in the most effective, least wasteful way. • gives us far better scalability and maintainability
  • 3. • Generic to explicit We start out with the most generic, low-level, catch-all, unremarkable styles, and eventually progress to more explicit and specific rules as we move through the project. We might start with our reset, then progress to slightly more scoped rules like h1–6 {} , right through to extremely explicit rules such as .text-center {} . Read more at http://technotif.com/manage-large-css-projects-with-itcss/#qKXhAprDAHwLVGpw.99 • Low specificity to high specificity The lowest-specificity selectors appear towards the beginning, with specificity steadily increasing as we progress through the project. We want to ensure that we avoid as much of the Specificity Wars as we can, so we try and refrain from writing higher-specificity selectors before lower-specificity ones. We’re always adding specificity in the same direction, thus avoiding conflicts. • Far-reaching to localised Selectors towards the beginning of the project affect a lot of the DOM, with that reach being progressively lessened as we go through the codebase. We want to make ‘passes’ over the DOM by writing rules that affect progressively less and less of it. We might start by wiping the margins and paddings off everything, then we might style every type of element, then narrow that down to every type of element with a certain class applied to it, and so on. It is this gradual narrowing of reach that gives us the triangle shape. Ordering our projects according to these key metrics has several benefits. We can begin to share global and far-reaching styles much more effectively and efficiently, we vastly reduce the likelihood of specificity issues, and we write CSS in a logical and progressive order. This means greater extensibility and less redundancy, which in turn means less waste and much smaller file sizes.
  • 4.
  • 5. • Settings If you are using a preprocessor, start here. This holds any global settings for your project. Settings like $heading-size-1 should be defined all variables that holds values that uses • Tools mixins and functions. Any mixin or function that does not need accessing globally should belong in the partial to which it relates.Examples of global tools might be gradient mixins, font-sizing mixins and so on. • Generic high-level, far reaching styles. This layer is seldom modified,It contains things like Normalize. css, global box-sizing rules, CSS resets and so on. • Elements Elements layer binds onto bare HTML element (or ‘type’) selectors only. It is slightly more explicit than the previous layer in that we are now saying ‘make every h1 this big’ , or ‘make every a be a certain colour’. • Objects Users of OOCSS will be familiar with the concept of objects. This is the first layer in which we find class-based selectors. These are concerned with styling non-cosmetic design patterns, or ‘objects’. Objects can range from something as simple as a .wrapper element, to layout systems • Components The Components layer is where we begin to style recognisable pieces of UI. We’re still binding onto classes here, so our specificity hasn’t yet increased. However, this layer is more explicit than the last one in that we are now styling explicit, designed pieces of the DOM. • Trumps This layer beats – or ‘trumps’ – all other layers, and has the power to override anything at all that has gone before it. It is inelegant and heavyhanded, and contains utility and helper classes, hacks and overrides. A lot of the declarations in this layer will carry !important (e.g. .text-center { text-align: centre !important; } ). This is the highest specificity layer
  • 6. • @import “settings.global”; @import “settings.colors”; • @import “tools.functions”; @import “tools.mixins”; • @import “generic.box-sizing”; @import “generic.normalize”; • @import “elements.headings”; @import “elements.links”; • @import “objects.wrappers”; @import “objects.grid”; • @import “components.site-nav”; @import “components.buttons”; @import “components.carousel”; • @import “trumps.clearfix”; @import “trumps.utilities”; @import “trumps.ie8”;
  • 7. Object oriented css • Object-oriented CSS, at its core, is simply writing cleaner, DRYer CSS. It’s just a paradigm shift. The purpose of OOCSS is to encourage code reuse and, ultimately, faster and more efficient stylesheets that are easier to add to and maintain
  • 8. • OOCSS is based on two main principles: The first is to separate the structure from the skin : Layout and design styling are separate .In other words separation Colors, borders and other visual characteristics from styling background, color, animation ,border, etc. this means not to mix structure/positioning properties with skin/styling properties on the same class. The bad way The good way .button-1 { border: 1px solid #ccc; width: 50px; height: 50px; border-radius: 5px; } .button-2 { border: 1px solid #ccc; width: 70px; height: 20px ; border-radius: 5px; } button-1 { width: 50px; height: 50px; } .button-2 { width: 70px; height: 20px ; } .button-border { border: 1px solid #ccc; border-radius: 5px; }
  • 9. The second is to separate the container from the content: Break the dependency between the container module and the content objects it contains separating container from content,A styled element should never be dependent on where it’s at in a page Essentially, this means “rarely use location-dependent styles”. <input> with .call_info form .left_call_info input <input> , like <input class=“input_pos input_skin">. The bad way The good way .call_info form .left_call_info input { border: none; width: 400px; height: 30px; background-color: #e9e9e9; color: #122c49; padding-left: 5px; font-size: 10px; } .input_pos { width: 400px; height: 30px; padding-left: 5px; } .input_skin { background-color: #e9e9e9; color: #122c49; font-size: 10px; }
  • 10. What about semantic css? • You shouldn't care about being non-semantic The only way to make objects in plain CSS is to define non-semantic classes. However, this comes with some problems: • DOM will be overloaded. <a href="#" id=“click_it” class="btn border box-shadow btn-small btn-blue nice clickable">Click me!</a> • There's not a safe way to access some of the DOM elements. there is no best way so you have to choose what is good for particular case . document.getElementsByClassName(“clickable ”); x[0].innerHTML = "Hello World!"; Or document.getElementById(“click_it”); x.innerHTML = "Hello World!"; Or document.querySelectorAll(“.clickable ”); x[0].innerHTML = "Hello World!";
  • 11. Reusable CSS • OOCSSS encourage to avoid location dependent styles , you create smaller modules on the page and extend them with subclasses as necessary • Reusability is also improved because of the OOCSS encourages abstracting CSS structural styles and skin level styles.
  • 12. OOCSS & CSS Preprocessors • OOCSS and CSS preprocessors solve different problems • Object oriented CSS is an approach and methodology to achieve the goal while a preprocessor is a tool to support and enlarge the system.
  • 13. DRY CSS • OOCSS focused specifically on abstracting snippets of code, Dry Css focuses primarily on not repeating yourself.. • The core recommendation of Dry Css is to group reusable properties, name them and then add all selectors to the group.. • Avoid specificity by harnessing the cascade • Compared with the OOCSS framework, DRY CSS argues that semantic HTML should be HTML that reflects the content. • If the HTML is out of your control, it is obviously valuable, on the other hand it doesn’t necessarily encourage thoughtful HTML structuring.
  • 14. “Less” comes into play The extend directive allows us to easily share styles between selectors. The bad way The good way a.twitter { min-width: 100px; padding: 1em; border-radius: 1em; background: #55acee color: #fff; } span.facebook { min-width: 100px; padding: 1em; border-radius: 1em; background: #3b5998; color: #fff; } .button { min-width: 100px; padding: 1em; } .button-skin { border-radius: 1em; color: #fff; } .twitter-background { background: #55acee; } .facebook-background { background: #3b5998; } .btn { &--twitter { &:extend(.button); &:extend(.twitter-background); &:extend(.button-skin); } &--facebook { &:extend(.button); &:extend(.facebook-background); &:extend(.button-skin); } }
  • 15. Classes • According to most OOCSS methodologies, subclassing is always handled at the HTML level. It’s better to avoid attaching not more than 3-4 classes to a single element. When attaching a new class we have to increase semantic value as well as it necessary or it’s better to mix oocss with dry css. Compiled css Html Comparison .button, .btn--twitter, .btn--facebook { min-width: 100px; padding: 1em; } .button-skin, .btn--twitter, .btn--facebook { border-radius: 1em; color: #fff; } .twitter-background, .btn--twitter { background: #55acee; } .facebook-background, .btn--facebook { background: #3b5998; } <!-- css way --> <a href="#" class="twitter">Twitter</a> <a href="#" class="facebook">Facebook</a> <!– pure oocss way --> <a href="#" class="button-skin button btn--twitter ">Twitter</a> <a href="#" class="button-skin button btn--facebook ">Facebook</a> <!-- dry oocss way with less --> <a href="#" class=“btn--facebook">Twitter</a> <a href="#" class=“btn--twitter">Facebook</a>
  • 16. Mixins and OOCSS • With preprocessors, we can define so-called "mixins", which have some similarities to functions in programming languages. In I suggest you to don’t include mixin when you don’t give it arguments , you can just use extend and take dry css as we mentioned in past slides or you can just attach it in your html because dry preprocessor code does not mean dry css code when we compile our code to css we will end up with repetitions of various properties. .round(@radius: 5px) { /* Safari 3-4, iOS 1-3.2, Android 1.6- */ -webkit-border-radius: @radius; /* Firefox 1-3.6 */ -moz-border-radius: @radius; /* Opera 10.5, IE 9, Safari 5, Chrome, Firefox 4, iOS 4, Android 2.1+ */ border-radius: @radius; } .form-info { background-color: #ccc; border: 2px solid rgba(0,0,0,0.7); .round( 15px) ; }
  • 17. Some suggestions to avoid specificity • Avoid to use IDs in CSS, (anything you can do with an ID, you can do with a class), ID or just selecte it with just attribute selector [id = “some_id”] • Do not nest selectors unnecessarily. • Do not qualify selectors unless you have a compelling reason to do so. If.nav {} will work, do not use ul.nav {}; to do so would not only limit the places you can use the . • Make heavy use of classes because they are the ideal selector: low specifity great portability, and high reusability. • Safely increasing specificity .btn.btn { } …will select based on only one class (.btn) but with double the specificity. We can take this as far as we need to:.btn.btn.btn.btn { }it just asks the same question n times. • Never use !importantant !important declarations should not be used unless they are absolutely necessary after all other avenues have been exhausted. It ruins the order • Descending order of specificity 1. Inline styles 2. ID selectors – (#big) 3. Pseudo Classes (:hover), (:visited) etc. 4. Attributes Selectors – ([href=“”] , [target=“”]); 5. Class Selectors – (.clases) 6. Type Selectors (em, h1, p, ul, li) 7. Universal selectors – (*)
  • 18. Choose wisely from the toolkit: mixins, extends, a new module or subclass Mixins, extends and classes are tools that allow the reduction of repetition in the the act of writing CSS. Each of these however results in a very different outcome in the final compiled CSS and each comes with a potential pitfall. Overuse of mixins results in highly repetetive and bloated CSS, overuse of classes will start to feel like classitis, and an overuse of extends can result in too many selectors attatched to the same CSS rule. It’s important to find a good balance and have a process for deciding which solution to use.
  • 19. Avoid deep-nested selectors and selectors tightly coupled to HTML • At first , when I started to use preprocessors I was very impressed about that I could write nested css styles and it was repeating the structure of the DOM , but my impression died when first I’ve compiled • So then I realized that to much nesting styles gives you unnecessary specificity and css downloading time is growing as the size of it, so then I found that there is some kind of theoretical border for nesting levels : “Note that objects should have at most 4 levels. Most of the time you'll stay around the 2-3 level range, and the fourth would be the interaction state.” http://thesassway.com/beginner/the-inception-rule • I prefer to use not more then 2 levels but there is always some cases when I really need but I am trying to keep in mind “don’t nested more then 4 levels” preprocessor code compiled .container { .menu-list { ul { list-style: none; li { padding-left: 10px; span { background-image: url() 0 0 no-repeat; } } } } } .container .menu-list ul { list-style: none; } .container .menu-list ul li { padding-left: 10px; } .container .menu-list ul li span { background-image: url() 0 0 no-repeat; }
  • 20. Conclusion• Ultimately, the key to successfully using OOCSS and preprocessors together is understanding the problems that OOCSS and preprocessors solve as well as the way the final CSS will compile. While CSS preprocessors offer a number of conveniences to front-end developers, they don’t guarantee efficient, maintainable and scalable code. By creating a clear folder/file structure, maintaining consistent naming conventions, avoiding deep-nested selectors or CSS/HTML coupling, and choosing wisely from the toolkit, it is possible to benefit from both OOCSS and preprocessors. • OOCSS sources: • https://github.com/stubbornella/oocss • http://www.slideshare.net/stubbornella/object-oriented-css?qid=311faf43-46d6-4441-88b0- b07dc8e3d8ab&v=qf1&b=&from_search=1 • http://appendto.com/2014/04/oocss/ • http://www.smashingmagazine.com/2011/12/an-introduction-to-object-oriented-css-oocss/ • http://cwebbdesign.tumblr.com/post/23666803241/scalable-and-maintainable-css-approaches • OCSS and preprocessor sources: • http://thesassway.com/intermediate/using-object-oriented-css-with-sass • http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/ • https://css-tricks.com/the-extend-concept/ • http://thesassway.com/intermediate/avoid-nested-selectors-for-more-modular-css • http://thesassway.com/beginner/the-inception-rule • http://alancrissey.com/articles/more-object-oriented-css-with-less/ • http://blog.mediumequalsmessage.com/guidelines-using-oocss-and-css-preprocessors