Skip to main content

CSS Coding Standards And Anatomy Of Internal, External & Inline CSS

 

CSS Coding Standards

I prefer CSS coding standards from wordpress.org (though you can write CSS in any way you want, only browsers should understand). So here is the list of coding standard I made (and add) from https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/.

PART-1

-> Naming selectors: use lowercase, separate words with hyphen (-); not with underscore (_) or camelcase (eg., commentForm).

-> Each selector should be in its own line, ending in either a comma or an opening curly brace. There should be no space b/w selector and comma; but there there should be a space b/w selector and opening curly brace.

-> Attribute selectors should use double quotes around values (eg., input[type="text"]).

-> Use Tab/s (not space/s) to indent each property. I prefer single Tab.

-> Each property / value pair should be in its own line; and ending with a semicolon (;). Property should be followed by a colon > a space > value > semicolon. Property / value should be lowercase, except for font names and vendor-specific properties.

-> Value 1/3: space before value, after a colon. And should end in semicolon. Define font weights in numerical values (e.g., 400, 700; instead of normal, bold). Use double quotes rather than single quotes. Use a leading zero for decimal values. Don't add a space between value and unit, for example "margin: 20px" is correct, and "margin: 20 px" is incorrect.

-> Value 2/3: don't pad parentheses with spaces.

-> Value 3/3: multiple comma-separated values for one property should be separated by a space (after the comma).

-> Use unit-less line height: see here why? http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/.

-> Colors: use hex code, or rgba() if opacity is needed. Use shorten values (#fff) when possible, instead of #FFFFFF. Avoid RGB format and uppercase.

-> The closing curly brace, should be flush left, with same level of selectors' indentation.

-> Line blanks: one line blank b/w blocks (in a section); two lines blank b/w sections.

-> Ordering: random ordering is chaos, not poetry. I prefer alphabetically ordering. Also consider the following order (for longer CSS), that I've seen in many Wordpress.org themes:
/**
* Table of Contents
*
* 1.0 - Normalize
* 2.0 - Genericons
* 3.0 - Typography
* 4.0 - Elements
* 5.0 - Forms
* 6.0 - Navigation
* 6.1 - Links
* 6.2 - Menus
* 7.0 - Accessibility
* 8.0 - Alignments
* 9.0 - Clearings
* 10.0 - Widgets
* 11.0 - Content
* 11.1 - Header
* 11.2 - Posts and pages
* 11.3 - Post Formats
* 11.4 - Comments
* 11.5 - Sidebar
* 11.6 - Footer
* 12.0 - Media
* 12.1 - Captions
* 12.2 - Galleries
* 13.0 - Multisite
* 14.0 - Media Queries
* 14.1 - >= 710px
* 14.2 - >= 783px
* 14.3 - >= 910px
* 14.4 - >= 985px
* 14.5 - >= 1200px
* 15.0 - Print
*/

PART-2

Grouping selectors & CSS Shorthand

Grouping selectors example:

selector1,
selector2,
Selector3 {
...
}

CSS shorthand examples for (1) font, (2) background, (3) margin, (4) border, (5) padding and (6) list.

Note: use single space (not a comma) between each property. Use "a comma and single space" to separate fonts from each other.

(1) font: font-size must be followed by font-family and a semicolon; other properties should come before font-size without any order. Example:

p  {
font: bold italic small-caps 1.5em Georgia, Times, Serif;
}

(2) background: sequence is like that, background-image, background-position, background-repeat, background-attachment, background-color. See example below:

body  {
background: url(child.jpg) right top no-repeat fixed #ddd;
}

(3) margin: sequence in margin, TRBL (Trouble), that is Top - Right - Bottom - Left.

Rule that I read from The Definitive Guide by Eric A. Meyer was like in my words:

(#) If there is a single value, take it as the value of Top [added from my side].
(#) If value of Right is missing, take the value of Top.
(#) If value of Bottom is missing, take the value of Top.
(#) If value of Left is missing, take the value of Right.

Example 1: margin 50px for Top, Right, Bottom and Left.

.div-two  {
margin: 50px ;
}

Example 2: margin 125px for Top and Bottom; margin 100px for Right and Left.

.div-two {
margin: 125px 100px;
}

Example 3: margin 100px Top, margin 200px Bottom, margin 100px Right and Left.

.div-two  {
margin: 100px 100px 200px;
}

(4) border: order in properties doesn't matter, you can write in any way you want, but don't forget using semicolon at the end.

.div-two  {
border: #fff 4px solid;
}

(5) padding: sequence in padding works like margin, so I'm leaving it.

(6) list: sequence in shorthand of list is, list-style-type, list-style-image, and, list-style-position

ul  {
list-style: disc url(arrow-circle-right.svg) inside;
}

Anatomy of internal & external CSS

Remember few things and you will remember CSS anatomy even in your dreams: selector, curly-bracket-start, property, colon, a space, value, semicolon, curly-bracket-end. That't it.

Example:

body  {
background-color: #ddd;
}

Anatomy of internal and external CSS is the same, only there is a matter of placing CSS. With internal we place CSS with in <head> </head>, and between <style> </style> element. And with external we place CSS outside in a file with .css extension (e.g., style.css) and between <head> </head> provide the link of that file, see example 2.

Example 1:

<head>
<style>
body {
background-color: #ddd;
}
</style>
</head>

Example 2:

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

Anatomy of inline CSS

In inline CSS, we don't use curly braces, but use double quotes instead. And it is written like the following example, anywhere between <body> </body> element.

<body>
<p style="color:#00B746;"> Hello !</p>
</body>

Comments

Popular posts from this blog

Golden Rule Of Three Years To Get Success

Give yourself completely to whatever you like for three years -- let it be your career, business, health or any other thing of life. Why three years, exactly? Because what is the advantage of sticking to something which isn't giving any result. Time is precious, don't waste if the results aren't coming. Why not less than three years? If we spread these three years for success, we can assume first year is dominated by getting knowledge of the field, second year dominated by execution, and the third year comes the maturity where knowledge and experience of execution strike for success.  As an exeption we can stretch these three years into five or six years -- only when there are uncontrollable issues like of health or circumstantial issues.

Name List Of 64 Yogini / चौँसठ योगिनी

It is a list of 64 Yogini, if you want these names in Stotra form you can get from another post of this blog. These names are very useful for doing, Jaap, Puja, Tarpan, and Havan. These names are also used in making 64 Yogini Yantra in which there are 64 squares and in each square, name of each Yogini is written, then everyday worship of this Yantra starts.  For Pujan (Poojan): ओं ---------- देव्यै पूजियामि नम: ! (e.g., ओं गजानना देव्यै पूजियामि नम: ! ) For Tarpan: ओं ---------- देव्यै  तर्पयामि नम: ! (e.g., ओं गजानना देव्यै  तर्पयामि नम: !) Together Pujan+Tarpan: ओं ---------- देव्यै   पूजियामि / तर्पयामि नम:: ! (e.g., ओं गजानना देव्यै   पूजियामि / तर्पयामि नम:: ! ) For Jaap : ओं ---------- देव्यै नम:! (e.g., ओं गजानना देव्यै नम:!) For Havan:  ओं ---------- देव्यै स्वाहा ! (e.g., ओं गजानना देव्यै स्वाहा !) Note: in the empty space ( ---------- ) you can fill the name of each yogini for each time. List of 64 Yogini / चौँसठ योगिनी For better readability I put this list in four parag

108 Names Of Shri Surya From Mahabharata

Surya (Sun) is the most important planet as well as a deity. Worshiping Surya increases prana-shakti (life-force), it rays destroy many diseases and it is the biggest source of never ending energy. There is a Strota, called Surya-Kavach, it is chanted for protection, as a deity his protection is very strong — remember the case of Karna in Mahabharata, he was invincible due to Surya-Kavach. This Surya-Kavach wasn’t as it is shown in movies, it was a Mantrik protection which Karna had and on Indra request he promised not to use it in the war. We take note of popular deities, but Surya as a deity is not lesser than others — though there are less Sanskrit literature on Surya (as I know), but whatever it is, like Surya Kavach and Aditya Hriday Strota, I think, is very potent. English Name | हिंदी नाम 1) Om Suryaay Namah | ॐ सूर्याय नम: 2) Om AryMane Namah | ॐ अर्यमणे नम:

Devi Lalita Vrat & Puja Vidhi

 This festival is celebrated on Bhadon Vadi Chhath. It is for Devi Lalita, this day she is worshiped. Women worship Devi Lalita by Vrat and Puja, ‘coz they want to see the Goddess as their friend. And as a friend Devi is supposed to solve their problems of life and fulfil other genuine wishes. गंगा द्वारे कुशावंते विल्वके नील पर्वते ॥ स्नात्वा कनखले देवि हरं लब्धवतीं पतितं ॥ ललिते सुभगे देवी सुख सौभाग्य दायिनी ॥ अनंतं देहि सौभाग्यम मह्यं तुम्भ नमोनमः:॥ In her worship, above stotra is chanted which means — हे देवी ! आपने गंगाद्वार, विल्वक, नीलपर्वत एवं कनखल इत्यादि पवित्र तीर्थो में स्नान कर भगवान शंकर को पति के रूप में वरण किया है, हे सौभाग्यदायिनी देवी ललिता आपको नमस्कार करता हूँ (करती हूँ ) ।

Mantra To Remove Poverty & Attract Lakshmi On Diwali

 Here are few things that previous generations used to do on Diwali. Mantra to remove poverty: This mantra is often chanted to beat away the poverty from the home. This is ritualistic where people imagine “poverty” and other kinds of negativity are going away and home is getting purer and cleaner to attract goddess Lakshmi. काने भेड़े दुखदायी दरिद्र तू मेरे घर से जा अब भाग ॥ देवी भगवती लक्ष्मी आई, तज घर मेरा और जा भाग ॥ डंडा बजाऊ मार लगाऊ नहीं तो जा अब भाग ॥ लक्ष्मी जी का वास हो गया मेरे यहाँ, तेरा नहीं निस्तार ॥ Mantra to attract Lakshmi:

10 Names Of Shri Batuk Bhairav From Agam Rahasya

These ten names of Shri Batuk Bhairav from Agam Rahasya are in stotra form. please check below. If you worship Shri Batuk then these name stotra should be learned by heart. Without remembering and worshiping Him no Chandi / Durga Puja gets completed 'coz He is the Ang Devta of Devi. He is supposed to be pleased easily and protects our family, home and belongings.  अद्याद्यो हेतुबटुको द्वितीयो बटुक स्मृतः । त्रिपुरान्तक बटुकस्तृतीयः परिकीर्तितः ।। वह्निवेताल बटुकश्चतुर्थः कीर्तितः शिवेन अथाग्निजिह्वबटुक पञ्चमः परिकीर्तितः ।। श्रीकालबटुकस्तद्वत् करालबटुकस्तथा । तथैकपाद बटुकः श्री भीमबटुकस्तथा ।।  त्रैलोक्य बटुकश्चैव श्री सिद्धबटुकस्तथा । दश वै बटुका ख्याताः सर्व सिद्धि प्रदायकाः ।।

Organising the mind and creating something wonderful

 I work from home as many people do. When I get up in the morning, I often get confused either to take a bath, a walk, watch tv — or do my work. And when I open my PC, still there are so many things: backing up files, mainly databases, managing usernames and passwords, reading emails, and there is always a chance to get lost in social media, facebook, twitter and other things. After an hour or two, I find that I’ve messed up everything. But this must not go everyday….. So I need to use a willpower? Kind of motivation, inspiration that I need to do only prioritise work: what is important, first; second important, second; third important, third; and so on. But in my case, will power often fails — it makes me inflexible, arrogant, dry of ideas and playfulness. And I find myself just doing nothing, it's just willpower and determination that break my back.

Twelve (12) Names Of Kashi (Varanasi)

 In India most people just know three names of (1) Kashi; two others — (2) Banaras, (3) Varanasi. But there are 12 more names too written in Skanda Puran; they are as followings: १) LolarKaay | लोलार्काय २) UttrarKaay | उत्तरार्काय ३) SambaditYaay | साम्बादित्याय ४) DrupadaditYaay | द्रुपदादित्याय ५) MayukhaditYaay | मयूखादित्याय ६) KhaKholkaditYaay | खखोल्कादित्याय ७) ArunaditYaay | अरुणादित्याय ८) VradhaditYaay | वृद्धादित्याय १०) KeshwaditYaay | केशवादित्याय ११) VimladitYaay | विमलादित्याय १२) YamaditYaay | यमादित्याय