ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
CSS BEST PRACTICES By Sachin Chaudhari ¨C Zensar Technologies
Introduction This Presentation is consolidation of the CSS (Cascading Style Sheet) best practices during web development.
Advantages of CSS CSS helps to reduce html code Pages load faster Easy for maintenance  Saves time
Types of CSS Inline styles Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to. <a href=&quot;&quot; style=&quot;text-decoration: none;&quot;> Embedded/Internal styles Embedded or Internal styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in. <style type=&quot;text/css¡°> p { color: #00f; } </style> External styles External styles are styles that are written in a separate document and then attached to various documents. External style sheets can affect any document they are attached to. <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot; />
CSS Best Practices Use a Reset Resets essentially eliminate browser inconsistencies such as heights, font sizes, margins, headings, etc. The reset allows your layout look consistent in all browsers.  Example: body, h1,h2,h3,h4,h5,h6,form,fieldset,input,textarea,p {  margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset,img {  border:0; } ol,ul { list-style:none; }
CSS Best Practices Organize the Stylesheet with a logical Structure lay your stylesheet out in a way that allows you to quickly find parts of your code.  So, an example stylesheet might be ordered like this: Generic classes (body, a, p, h1, etc.) /* header ****/ styles goes here... /* header End****/ /* main content ****/ styles goes here... /* main content End****/ /* footer ****/ styles go here... /* footer End ****/ /* common****/ styles go here... /* common End ****/
CSS Best Practices Make it Readable The readability of your CSS is incredibly important, though most people overlook why it's important. Great readability of your CSS makes it much easier to maintain in the future, as you'll be able to find elements quicker.  Also, you'll never know who might need to look at your code later on.  All on one line .content { background: red; padding: 2em; border: 1px solid black; } on different line .content {  background: red;  padding: 2em;  border: 1px solid black;  }
CSS Best Practices Keep it Consistent Along the lines of keeping your code readable is making sure that the CSS is consistent.  develop your own &quot;sub-language&quot; of CSS that allows you to quickly name things.  There are certain classes that I create in nearly every application, and I use the same name each time. For example, I use &quot;.dbfl&quot; to float divs to the left. Good Example .dbfl { display:block;  float:left; } .dbfr { display:block;  float:right; } Bad Example .dbfl { display:block;  float:left; } .dbfr { float:right; display:block; }
CSS Best Practices Combine Elements Elements in a stylesheet sometimes share properties.  Instead of re-writing the same properties just combine them. For example, your h1, h2, and h3 elements might all share the same font and color: h1, h2, h3 {font-family: tahoma, color: #333}
CSS Best Practices Use Multiple Classes Sometimes it's beneficial to add multiple classes to an element.  Let's say that you have a <div> having class &quot;box&quot; which defines color and font properties .  <div class=&quot;box&quot;></div> Now you want to float it right, and you've already got a class . right  in your CSS that floats everything to the right. You can simply add an extra class in the declaration, like so: <div class=&quot;box right&quot;></div>
CSS Best Practices Use Shorthand while declarations Comment your CSS  Avoid Using Inline Styles
CSS Best Practices Validate your CSS Validating your CSS does more than give a sense of pride:  it helps you quickly spot errors in your code. Validation Service http://jigsaw.w3.org/css-validator/
THANK YOU

More Related Content

What's hot (15)

CSS
CSSCSS
CSS
seedinteractive
?
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
priyadharshini murugan
?
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
Evolution Network
?
Css introduction
Css   introductionCss   introduction
Css introduction
AbhishekMondal42
?
Week 12 CSS - Review from last week
Week 12 CSS - Review from last weekWeek 12 CSS - Review from last week
Week 12 CSS - Review from last week
Katherine McCurdy-Lapierre, R.G.D.
?
CSS
CSSCSS
CSS
anandha ganesh
?
Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)
Harshil Darji
?
Web Design, Lesson Plan: Classes and IDs
Web Design, Lesson Plan: Classes and IDsWeb Design, Lesson Plan: Classes and IDs
Web Design, Lesson Plan: Classes and IDs
Steve Kinney
?
Html css
Html cssHtml css
Html css
kanakaiah kedam
?
Html Expression Web
Html Expression WebHtml Expression Web
Html Expression Web
Mark Frydenberg
?
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2
Jeff Byrnes
?
Week3 css
Week3 cssWeek3 css
Week3 css
Rowena LI
?
CSS introduction
CSS introductionCSS introduction
CSS introduction
CloudTech?
?
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
Swati Sharma
?
Css
CssCss
Css
Anuj Singh Rajput
?

Viewers also liked (12)

Search For Buzz Sc Bilbao 2010, Massimo Burgio
Search For Buzz Sc Bilbao 2010, Massimo BurgioSearch For Buzz Sc Bilbao 2010, Massimo Burgio
Search For Buzz Sc Bilbao 2010, Massimo Burgio
search congress
?
Atlassian confluence: how to change font size
Atlassian confluence: how to change font sizeAtlassian confluence: how to change font size
Atlassian confluence: how to change font size
StepShot
?
¹ó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦ÓÃ
¹ó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦Óùó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦ÓÃ
¹ó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦ÓÃ
taobao.com
?
Extending Slate Queries & Reports with JSON & JQUERY
Extending Slate Queries & Reports with JSON & JQUERYExtending Slate Queries & Reports with JSON & JQUERY
Extending Slate Queries & Reports with JSON & JQUERY
Jonathan Wehner
?
Python profiling
Python profilingPython profiling
Python profiling
dreampuf
?
Getting Started in the Mobile Web
Getting Started in the Mobile WebGetting Started in the Mobile Web
Getting Started in the Mobile Web
Brian Fling
?
Android App Development (Basics)
Android App Development (Basics)Android App Development (Basics)
Android App Development (Basics)
Alberto Rubalcaba Stockman
?
´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ
´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ
´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ
greengnn
?
ÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkit
ÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkitÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkit
ÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkit
LainZQ
?
Testing Content Effectiveness - Penn State 2015
Testing Content Effectiveness - Penn State 2015Testing Content Effectiveness - Penn State 2015
Testing Content Effectiveness - Penn State 2015
NewCity
?
Not my type font
Not my type fontNot my type font
Not my type font
Simon Stratford
?
Lawless font
Lawless fontLawless font
Lawless font
Simon Stratford
?
Search For Buzz Sc Bilbao 2010, Massimo Burgio
Search For Buzz Sc Bilbao 2010, Massimo BurgioSearch For Buzz Sc Bilbao 2010, Massimo Burgio
Search For Buzz Sc Bilbao 2010, Massimo Burgio
search congress
?
Atlassian confluence: how to change font size
Atlassian confluence: how to change font sizeAtlassian confluence: how to change font size
Atlassian confluence: how to change font size
StepShot
?
¹ó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦ÓÃ
¹ó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦Óùó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦ÓÃ
¹ó±ô²¹²õ³óÓëÔöÇ¿Ðͷɱð²úÓ¦ÓÃ
taobao.com
?
Extending Slate Queries & Reports with JSON & JQUERY
Extending Slate Queries & Reports with JSON & JQUERYExtending Slate Queries & Reports with JSON & JQUERY
Extending Slate Queries & Reports with JSON & JQUERY
Jonathan Wehner
?
Python profiling
Python profilingPython profiling
Python profiling
dreampuf
?
Getting Started in the Mobile Web
Getting Started in the Mobile WebGetting Started in the Mobile Web
Getting Started in the Mobile Web
Brian Fling
?
´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ
´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ
´Óä¯ÀÀÆ÷äÖȾ¿´±ê×¼µÄÖØÒªÐÔ
greengnn
?
ÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkit
ÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkitÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkit
ÕâÄêÍ·£¬ÄãÖ»ÐèÒª¶®Node webkit
LainZQ
?
Testing Content Effectiveness - Penn State 2015
Testing Content Effectiveness - Penn State 2015Testing Content Effectiveness - Penn State 2015
Testing Content Effectiveness - Penn State 2015
NewCity
?

Similar to Css Best Practices (20)

Introduction to css
Introduction to cssIntroduction to css
Introduction to css
Joseph Gabriel
?
CSS-part-1.ppt
CSS-part-1.pptCSS-part-1.ppt
CSS-part-1.ppt
AshwaniKumarYadav19
?
Basics Of Css And Some Common Mistakes
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
sanjay2211
?
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introduction
apnwebdev
?
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
Tom Hapgood
?
CSS 101
CSS 101CSS 101
CSS 101
dunclair
?
Css
CssCss
Css
NIRMAL FELIX
?
Cascading style sheet, CSS Box model, Table in CSS
Cascading style sheet, CSS Box model, Table in CSSCascading style sheet, CSS Box model, Table in CSS
Cascading style sheet, CSS Box model, Table in CSS
SherinRappai
?
Rational HATS and CSS
Rational HATS and CSSRational HATS and CSS
Rational HATS and CSS
Strongback Consulting
?
Css introduction
Css introductionCss introduction
Css introduction
Sridhar P
?
Unitegergergegegegetgegegegegegeg-2-CSS.pptx
Unitegergergegegegetgegegegegegeg-2-CSS.pptxUnitegergergegegegetgegegegegegeg-2-CSS.pptx
Unitegergergegegegetgegegegegegeg-2-CSS.pptx
VikasTuwar1
?
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
SURYANARAYANBISWAL1
?
AK css
AK cssAK css
AK css
gauravashq
?
IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
?
Css Basics
Css BasicsCss Basics
Css Basics
Jay Patel
?
Css
CssCss
Css
Jahid Blackrose
?
Css introduction
Css  introductionCss  introduction
Css introduction
vishnu murthy
?
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
Sanjoy Kr. Paul
?
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
nikhilsh66131
?
Casc Style Sheets Ii
Casc Style Sheets IiCasc Style Sheets Ii
Casc Style Sheets Ii
Digital Insights - Digital Marketing Agency
?

Recently uploaded (20)

Introductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptxIntroductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptx
khaledsameh950
?
POC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptx
POC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptxPOC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptx
POC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptx
anikogiant
?
Jalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts Hoodie
Jalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts HoodieJalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts Hoodie
Jalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts Hoodie
TeeFusion
?
edit power------------oooppppppppppppppoint.pptx
edit power------------oooppppppppppppppoint.pptxedit power------------oooppppppppppppppoint.pptx
edit power------------oooppppppppppppppoint.pptx
sarikasharma627282
?
Testttt5ttttttttttttttttpower point.pptx
Testttt5ttttttttttttttttpower point.pptxTestttt5ttttttttttttttttpower point.pptx
Testttt5ttttttttttttttttpower point.pptx
sarikasharma627282
?
Classroom Management that will tmotivate
Classroom Management that will tmotivateClassroom Management that will tmotivate
Classroom Management that will tmotivate
SherifsStorytime
?
L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...
L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...
L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...
Casa Netural
?
70's are Back Agency by ºÝºÝߣsadfdgo.pptx
70's are Back Agency by ºÝºÝߣsadfdgo.pptx70's are Back Agency by ºÝºÝߣsadfdgo.pptx
70's are Back Agency by ºÝºÝߣsadfdgo.pptx
khaledsameh950
?
Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...
Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...
Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...
samtheg92
?
"Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska...
"Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska..."Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska...
"Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska...
Fwdays
?
General Space and Zoning Bubble diagram for Hospital
General Space and Zoning Bubble diagram for HospitalGeneral Space and Zoning Bubble diagram for Hospital
General Space and Zoning Bubble diagram for Hospital
JhonxD10
?
water_cycle.ppt vishana ppt 55?555566666
water_cycle.ppt vishana ppt 55?555566666water_cycle.ppt vishana ppt 55?555566666
water_cycle.ppt vishana ppt 55?555566666
patelvishana99
?
What is 3D Visualization? A Simple Guide for Beginners
What is 3D Visualization? A Simple Guide for BeginnersWhat is 3D Visualization? A Simple Guide for Beginners
What is 3D Visualization? A Simple Guide for Beginners
Zealous Services
?
Volodymyr Zelensky Thank You America Shirt
Volodymyr Zelensky Thank You America ShirtVolodymyr Zelensky Thank You America Shirt
Volodymyr Zelensky Thank You America Shirt
robintex21
?
The CLEAR Brands CLEAR EFX Branding Guide
The CLEAR Brands CLEAR EFX Branding GuideThe CLEAR Brands CLEAR EFX Branding Guide
The CLEAR Brands CLEAR EFX Branding Guide
Adriana Yankey
?
Simple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptxSimple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptx
josmaryguerraur
?
TLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptx
TLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptxTLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptx
TLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptx
Jely Bermundo
?
Design Strategy - working in-house on a team
Design Strategy - working in-house on a teamDesign Strategy - working in-house on a team
Design Strategy - working in-house on a team
Ariana Koblitz
?
Ramadhan 2 Large.pdfRamadhan 2 Large.pdf
Ramadhan 2 Large.pdfRamadhan 2 Large.pdfRamadhan 2 Large.pdfRamadhan 2 Large.pdf
Ramadhan 2 Large.pdfRamadhan 2 Large.pdf
SuryaDharma65
?
Simple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptxSimple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptx
josmaryguerraur
?
Introductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptxIntroductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptx
khaledsameh950
?
POC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptx
POC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptxPOC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptx
POC ONT FIBERHOMEPOC ONT FIBERHOMEPOC ONT FIBERHOME.pptx
anikogiant
?
Jalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts Hoodie
Jalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts HoodieJalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts Hoodie
Jalen Hurts Love Hurts Hoodie Jalen Hurts Love Hurts Hoodie
TeeFusion
?
edit power------------oooppppppppppppppoint.pptx
edit power------------oooppppppppppppppoint.pptxedit power------------oooppppppppppppppoint.pptx
edit power------------oooppppppppppppppoint.pptx
sarikasharma627282
?
Testttt5ttttttttttttttttpower point.pptx
Testttt5ttttttttttttttttpower point.pptxTestttt5ttttttttttttttttpower point.pptx
Testttt5ttttttttttttttttpower point.pptx
sarikasharma627282
?
Classroom Management that will tmotivate
Classroom Management that will tmotivateClassroom Management that will tmotivate
Classroom Management that will tmotivate
SherifsStorytime
?
L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...
L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...
L¨´dica didactica (Report finale residenza Diego Alatorre Go_Innovation a Casa...
Casa Netural
?
70's are Back Agency by ºÝºÝߣsadfdgo.pptx
70's are Back Agency by ºÝºÝߣsadfdgo.pptx70's are Back Agency by ºÝºÝߣsadfdgo.pptx
70's are Back Agency by ºÝºÝߣsadfdgo.pptx
khaledsameh950
?
Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...
Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...
Ch 12 Sound 2.pptbhcycygucuhbmmmmmntydtscudbddibudbd7dbdudbudbdudvdydvs6evs7v...
samtheg92
?
"Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska...
"Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska..."Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska...
"Seeing vs. Understanding: The Hidden Psychology of Design", Irene Shkarovska...
Fwdays
?
General Space and Zoning Bubble diagram for Hospital
General Space and Zoning Bubble diagram for HospitalGeneral Space and Zoning Bubble diagram for Hospital
General Space and Zoning Bubble diagram for Hospital
JhonxD10
?
water_cycle.ppt vishana ppt 55?555566666
water_cycle.ppt vishana ppt 55?555566666water_cycle.ppt vishana ppt 55?555566666
water_cycle.ppt vishana ppt 55?555566666
patelvishana99
?
What is 3D Visualization? A Simple Guide for Beginners
What is 3D Visualization? A Simple Guide for BeginnersWhat is 3D Visualization? A Simple Guide for Beginners
What is 3D Visualization? A Simple Guide for Beginners
Zealous Services
?
Volodymyr Zelensky Thank You America Shirt
Volodymyr Zelensky Thank You America ShirtVolodymyr Zelensky Thank You America Shirt
Volodymyr Zelensky Thank You America Shirt
robintex21
?
The CLEAR Brands CLEAR EFX Branding Guide
The CLEAR Brands CLEAR EFX Branding GuideThe CLEAR Brands CLEAR EFX Branding Guide
The CLEAR Brands CLEAR EFX Branding Guide
Adriana Yankey
?
Simple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptxSimple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Blue variant by ºÝºÝߣsgo.pptx
josmaryguerraur
?
TLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptx
TLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptxTLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptx
TLE-GRADE 9-CLASSIFICATION OF DESSERTS AND THEIR CHARACTERISTICS.pptx
Jely Bermundo
?
Design Strategy - working in-house on a team
Design Strategy - working in-house on a teamDesign Strategy - working in-house on a team
Design Strategy - working in-house on a team
Ariana Koblitz
?
Ramadhan 2 Large.pdfRamadhan 2 Large.pdf
Ramadhan 2 Large.pdfRamadhan 2 Large.pdfRamadhan 2 Large.pdfRamadhan 2 Large.pdf
Ramadhan 2 Large.pdfRamadhan 2 Large.pdf
SuryaDharma65
?
Simple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptxSimple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptx
Simple Style Thesis Defense Pink variant by ºÝºÝߣsgo.pptx
josmaryguerraur
?

Css Best Practices

  • 1. CSS BEST PRACTICES By Sachin Chaudhari ¨C Zensar Technologies
  • 2. Introduction This Presentation is consolidation of the CSS (Cascading Style Sheet) best practices during web development.
  • 3. Advantages of CSS CSS helps to reduce html code Pages load faster Easy for maintenance Saves time
  • 4. Types of CSS Inline styles Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to. <a href=&quot;&quot; style=&quot;text-decoration: none;&quot;> Embedded/Internal styles Embedded or Internal styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in. <style type=&quot;text/css¡°> p { color: #00f; } </style> External styles External styles are styles that are written in a separate document and then attached to various documents. External style sheets can affect any document they are attached to. <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot; />
  • 5. CSS Best Practices Use a Reset Resets essentially eliminate browser inconsistencies such as heights, font sizes, margins, headings, etc. The reset allows your layout look consistent in all browsers. Example: body, h1,h2,h3,h4,h5,h6,form,fieldset,input,textarea,p { margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset,img { border:0; } ol,ul { list-style:none; }
  • 6. CSS Best Practices Organize the Stylesheet with a logical Structure lay your stylesheet out in a way that allows you to quickly find parts of your code. So, an example stylesheet might be ordered like this: Generic classes (body, a, p, h1, etc.) /* header ****/ styles goes here... /* header End****/ /* main content ****/ styles goes here... /* main content End****/ /* footer ****/ styles go here... /* footer End ****/ /* common****/ styles go here... /* common End ****/
  • 7. CSS Best Practices Make it Readable The readability of your CSS is incredibly important, though most people overlook why it's important. Great readability of your CSS makes it much easier to maintain in the future, as you'll be able to find elements quicker. Also, you'll never know who might need to look at your code later on. All on one line .content { background: red; padding: 2em; border: 1px solid black; } on different line .content { background: red; padding: 2em; border: 1px solid black; }
  • 8. CSS Best Practices Keep it Consistent Along the lines of keeping your code readable is making sure that the CSS is consistent. develop your own &quot;sub-language&quot; of CSS that allows you to quickly name things. There are certain classes that I create in nearly every application, and I use the same name each time. For example, I use &quot;.dbfl&quot; to float divs to the left. Good Example .dbfl { display:block; float:left; } .dbfr { display:block; float:right; } Bad Example .dbfl { display:block; float:left; } .dbfr { float:right; display:block; }
  • 9. CSS Best Practices Combine Elements Elements in a stylesheet sometimes share properties. Instead of re-writing the same properties just combine them. For example, your h1, h2, and h3 elements might all share the same font and color: h1, h2, h3 {font-family: tahoma, color: #333}
  • 10. CSS Best Practices Use Multiple Classes Sometimes it's beneficial to add multiple classes to an element. Let's say that you have a <div> having class &quot;box&quot; which defines color and font properties . <div class=&quot;box&quot;></div> Now you want to float it right, and you've already got a class . right in your CSS that floats everything to the right. You can simply add an extra class in the declaration, like so: <div class=&quot;box right&quot;></div>
  • 11. CSS Best Practices Use Shorthand while declarations Comment your CSS Avoid Using Inline Styles
  • 12. CSS Best Practices Validate your CSS Validating your CSS does more than give a sense of pride: it helps you quickly spot errors in your code. Validation Service http://jigsaw.w3.org/css-validator/