visit
Basic definition of Modular CSS
Modular CSS is the philosophy or methodology or an approach of breaking down webpage styling into smaller independent components that are consistent, reusable and hold on to its visual integrity in any part of the webpage. Significantly, CSS modules are crafted based on a set of guidelines (or principles) to create a collection of reusable building blocks. The core concept present throughout the various guidelines or methodologies is how to identify the smaller parts/components that make up a webpage and then how to construct them using a consistent naming pattern. To break this down for more clarity:Modular CSS is:
Additionally, CSS modules are:
Two major principles of OOCSS
OOCSS comprises of two main underlying guidelines/principles:I. Separation of structure and skin
Structure, in this case, consists of the properties of an object which determine how an object is laid out in a particular place on the page, such as height, margins, overflow, paddings, and width. While the skin of an object refers to an obvious visual properties such as colors, gradients, fonts, and shadows. Example:Normal CSS rules
.btn {
width: 150px;
height: 50px;
background: #FFF;
border-radius: 5px;
}
.btn-2 {
width: 150px;
height: 50px;
background: #000;
border-radius: 5px;
}
Applying OOCSS to the above CSS rules
.btn {
background: #FFF;
}
.btn-2 {
background: #000;
}
.link {
width: 150px;
height: 50px;
border-radius: 5px;
}
<a class="btn link" href="#">Home</a>
<a class="btn-2 link" href="#">Blog</a>
II. Separation of container and content
In this context, content refers to elements such as div, images, span, and paragraphs tags that are nested within other elements which are referred to as the containers. Example:Normal CSS rules
#navbar {
padding: 2px;
left: 0;
margin: 3px;
position: absolute;
width: 140px;
}
#navbar .list {
margin: 3px;
}
#navbar .list .list-header {
font-size: 16px;
color: red;
}
#navbar .list .list-content {
font-size: 12px;
color: #FFF;
background-color: red;
}
Applying OOCSS to the above CSS rules
.navbar {
padding: 2px;
left: 0;
margin: 3px;
position: absolute;
width: 140px;
}
.list {
margin: 3px;
}
.list-header {
font-size: 16px;
color: red
}
.list-content {
background-color: red;
color: #c3dacf;
font-size: 12px;
}
Conceptually, a block is a "Standalone entity that is meaningful on its own", while an element is "A part of a block that has no standalone meaning and is semantically tied to its block" and modifier is "A flag on a block or element. Use them to change appearance or behavior".
Example/Syntax.block{
/*CSS rules*/
}
/*Elements declared with 2 underscores, after block*/
.block__element{
/*CSS rules*/
}
/*Modifiers declared with 2 dashes, after block or after element*/
.block- -modifier {
/*CSS rules*/
}
/*Element and modifier together*/
.block__element--modifier {
/*CSS rules*/
}
Group reusable CSS properties together:
{
background-color: #fff;
border-color: #ccc;
}
{
background-color: #fff;
border-color: #bbb;
}
Name these groups logically:
#LIGHT-WHITE-BACKGROUND,
.light-white-background
{
background-color: #fff;
border-color: #ccc;
}
#MEDIUM-WHITE-BACKGROUND,
.medium-white-background
{
background-color: #fff;
border-color: #bbb;
}
Add your selectors to the various CSS groups:
#LIGHT-WHITE-BACKGROUND,
.translation,
.entry .wp-caption,
#full-article .entry img,
.recent-comment .comment-text,
.roundup h3,
.post-header-sharing,
#post-categories td.label,
#post-archive roundup h3,
.subscription-manager ol,
.light-white-background
{
background-color: #fff;
border-color: #ccc;
}
#MEDIUM-WHITE-BACKGROUND,
textarea:focus,
input:focus,
#author-email-form .input-focus,
#respond p input:focus,
.wpfc7 input:focus,
.medium-white-background
{
background-color: #fff;
border-color: #bbb;
}
1. Base rules are the defaults and are almost exclusively single element selectors. Attribute selectors, pseudo-class selectors, child selectors, or sibling selectors can also be classified as base rules.
2. Layout rules divide your web page into sections. Layouts hold one or more modules together.
3. Modules sit inside layout components and can sit within other modules as well.
4. State rules define how our modules or layouts will look in a particular state, whether it's hidden, expanded, active, or inactive. State rules describe how a module or layout looks on screens that are smaller or bigger, and in different views, such as the home page or the inside page. You apply states to the same element as a layout rule or as a base module class.
5. Theme rules act similarly to state rules because they describe how modules or layouts might appear.
Check the link below for example about SMACSS methodologiesReferences: