{Carrer web log} ←
CSS Specificity Coding Method
Monday, October 12, 2009 { 3 Comments }
Few days ago I was reading the interesting Four Bubbles Model that inspired to think some alternative ways to organize CSS code.One of the first thing you learn is the lower is better or:
.name {color:blue;}
.name {color:red;} /* the winner */
The class .name with red color overwrites .name with blue color.
So our logical assumption is the lower the objects are in the CSS they are more specific.
In the age before firebug I was spending a lot of time determining why "the color is red" and what part of CSS determines why should be red.
So if I order my CSS by their Specificity the search should be very easy, I should start from the bottom to the top. If you don’t understand how CSS Specificity here is CSS Specificity Cheat Sheet and some useful links.
Example:
Elementsp{}
a{}
ul li {}
Classes
.name{}
div.name{}
ID’s
#header{}
#sidebar{}
#footer{}
#sidebar li {}
Maybe most popular method now of CSS organization is thematic approach or we have something like:
- CSS Reset
- CSS Layout
- CSS Typography
- CSS Other
There is nothing wrong with this model and we can improve it by adding CSS Specificity.
Elements
Reset + Typography other elements
Classes
Layout Classes, Typography Classes other classes
ID’s
Layout ID and other ...
Here is practical demo .css file: CSS-Specificity-Model.css
Also live "lorem ipsum" working example: CSS-Specificity-Model.html
or you can download .zip of the example.
Note: The code used for this example is mainly taken from The Golden Grid - CSS Framework
In my opinion there is no perfect model for organizing your CSS, this model is just one way of approaching CSS.
Some other useful link and coding models:
Practical, maintainable CSS
Progressive Enhancement with CSS
What you think about this model?
3 Responses to “CSS Specificity Coding Method”
- // cpmaynard // 10/12/2009
-
// Vladimir
// 10/12/2009
@Christopher: That is exactly my point: Use what works best for you and your situation. If this model makes sense for your coding and organization and you can find things quickly (even without firebug) , great. That is why I sad there is no perfect coding model, there is model that works or doesn't work for you :)
-
// M. David Green
// 10/14/2009
Nicely put. I think anyone who's spent some time building CSS with the understanding that someone else may someday have to modify it will gravitate naturally to this way of thinking. (As often as not, that someone else is the same person who wrote the original code. After six months away from a project, it can be just as confusing as inheriting someone else's code, so there's a strong incentive to be organized.)
<< Home
About Me <<<
Name: Vladimir Carrer
vladocar [at] gmail.com
Location: Verona, Italy
I'm a web designer, developer, teacher, speaker, generally web addicted ...
My projects <<<
- AI Prompt Directory
- Hand Drawn Icons
- Font Design Inspiration
- Font Pairings
- Free SVG Cut File
- Upcoming NFT projects
- Discord Tutorials
- Free Sublimation Designs
- Tech Feed
- MySQL Lite Administrator
- Quark Mini PHP CMS
- Formy - CSS Form Framework
- Emastic - CSS Framework
- Malo - CSS Library
- The Golden Grid
- 1 line CSS Grid Framework
- Two Lines CSS Framework
- Child Selector System - CSS Framework
- Better Web Readability Project
- Azbuka - CSS Typographical Base Rendering Library
- ClipR - bookmarklet for better reading
- CSS3 Action Framework
- CSS Mini Reset
- HTML5 Mini Template
- CSS Mobile Reset
- picoCSS - JavaScript Framework
- HTML Lorem Ipsum Crash Test
- Object Auto Documentation - JavaScript
- o - JS Library for Object Manipulation
- Foxy - CSS Framework
- Tumblr Free Theme - Better Readability Project
- Box - CSS Framework
- SMART CSS GRID
- nanoJS - Minimal JS DOM Library
- Flexy CSS Framework
- Katana is CSS Layout System made with Flexbox
- Micro CSS Reset
- 60 Grid System
- Simple CSS Button
- ramd.js JavaScript library for making web applications.
- Minimal Notes web app build with Vue.js
- Scribble Font for Prototyping & Wireframing
- Flex One - 1 CSS Class System
- Floaty - CSS Float Based Layout System
- Infinity CSS Grid
- CLI Convert websites into readable PDFs
- keywords-extract - CLI tool, extract keywords from any web page.
- screenshoteer - Make website screenshots and mobile emulations from the command line.
- Basic.css - Classless CSS Starter File
§§Previous Posts <<<
- Designing typographical wallpapers for iPhone
- CSS Specificity - Cheat Sheet
- Blog prototyping with Emastic using the Golden Pro...
- 4 useful Bookmarklet for Twitter, Google, CSS, SEO
- Twitter Unofficial Redesign
- Integration of Better Web Readability Project with...
- 1 line CSS Grid Framework
- O rule + golden proportion for calculating the gut...
- How we read on web and how can we improve that
- Geo Twitter (#ll)
Other Profiles <<<
Content is licensed under a Creative Commons Public Domain License