SlideShare a Scribd company logo
 
Efficient Maintainable, Modular By Gopinath Ambothi CSS
Writing efficient CSS
1 Use  external  style sheets instead of inline or header styles.
Not good:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> </head> <body> <p style= &quot; co lor: red &quot; > ... </p> </body> </html>
Not good:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <style type=&quot;text/css&quot; media=&quot;screen&quot;> p { color: red; } </style> </head> <body> ... </body> </html>
Good:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <link rel=&quot;stylesheet&quot; href=&quot;name.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /> <   /head> <body> ... </body> </html>
2 Use  link  rather than  @import  for IE & NN4
Not good:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <style type=&quot;text/css&quot; media=&quot;screen&quot;> @import url(&quot;styles.css&quot;); </style> </style> </head> <body> ... </body> </html>
Good:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <link rel=&quot;stylesheet&quot; href=&quot;name.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /> </head> <body> ... </body> </html>
Use  inheritance 3
Inefficient
p { font-family: arial, helvetica, sans-serif;   } #container {  font-family: arial, helvetica, sans-serif;  } #navigation {  font-family: arial, helvetica, sans-serif;  } #content {  font-family: arial, helvetica, sans-serif;  } #sidebar {  font-family: arial, helvetica, sans-serif;  } h1 {  font-family: georgia, times, serif;   }
Efficient
body { font-family: arial, helvetica, sans-serif;  } h1 { font-family: georgia, times, serif;  }
4 Use  multiple selectors
Inefficient
h1 {  color: #236799;  } h2 {  color: #236799;  } h3 {  color: #236799;  } h4 {  color: #236799;  }
Efficient
h1, h2, h3, h4 {   color: #236799;   }
5 Use  multiple declarations
Inefficient
p {   margin: 0 0 1em;   } p {   background: #ddd;   } p {   color: #666;   }
Efficient
p { margin: 0 0 1em; background: #ddd; color: #666; }
6 Use  shorthand properties
Inefficient
body { font-size : 85%; font-family : arial, helvetica, sans-serif; background-image : url(image.gif); background-repeat : no-repeat; background-position : 0 100%; margin-top : 1em; margin-right : 1em;  margin-bottom : 0;  margin-left : 1em;  padding-top : 10px; padding-right : 10px;  padding-bottom : 10px;  padding-left : 10px;   border-style : solid; border-width : 1px;  border-color : red;  color : #222222; }
Efficient
body { font : 85% arial, helvetica, sans-serif; background : url(image.gif) no-repeat 0 100%; margin : 1em 1em 0; padding : 10px; border : 1px solid red; color : #222; }
Writing maintainable CSS
Place a  time stamp, author and notation  at top of CSS files. 1
/* --------------------------------- Site:  Site name Author: Name  Updated: Date and time Updated by: Name --------------------------------- */
Include global  color notation 2
/* --------------------------------- COLORS Body background:  #def455 Container background:  #fff Main Text:  #333 Links:  #00600f Visited links: #098761 Hover links: #aaf433 H1, H2, H3: #960 H4, H5, H6: #000 --------------------------------- */
Use  meaningful  names for IDs & classes 3
Not Good:
.green-box { ... } #big-text { ... }
Better:
.pullquote {... } #introduction {... }
Group  related  rules 4
#header { ... } #header h1 { ... } #header h1 img { ... } #header form { ... } #header a#skip { ... } #navigation { ... } #navigation ul { ... } #navigation ul li { ... } #navigation ul li a { ... } #navigation ul li a:hover { ... } #content { ... } #content h2 { ... } #content p { ... } #content ul { ... } #content ul li { ... }
Add clear  comments  to your CSS files 5
/* --------------------------------- header styles --------------------------------- */ #header { ... } #header h1 { ... } #header h1 img { ... } #header form { ... } /* --------------------------------- navigation styles --------------------------------- */ #navigation { ... }
Modular  CSS (to be continued…)
Thank You!

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Efficient css

  • 1.  
  • 2. Efficient Maintainable, Modular By Gopinath Ambothi CSS
  • 4. 1 Use external style sheets instead of inline or header styles.
  • 6. <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> </head> <body> <p style= &quot; co lor: red &quot; > ... </p> </body> </html>
  • 8. <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <style type=&quot;text/css&quot; media=&quot;screen&quot;> p { color: red; } </style> </head> <body> ... </body> </html>
  • 10. <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <link rel=&quot;stylesheet&quot; href=&quot;name.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /> < /head> <body> ... </body> </html>
  • 11. 2 Use link rather than @import for IE & NN4
  • 13. <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <style type=&quot;text/css&quot; media=&quot;screen&quot;> @import url(&quot;styles.css&quot;); </style> </style> </head> <body> ... </body> </html>
  • 14. Good:
  • 15. <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;> <html lang=&quot;en&quot;> <head> <meta http-equiv=&quot;content-type&quot; content=&quot;text <title>Page title</title> <link rel=&quot;stylesheet&quot; href=&quot;name.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /> </head> <body> ... </body> </html>
  • 18. p { font-family: arial, helvetica, sans-serif; } #container { font-family: arial, helvetica, sans-serif; } #navigation { font-family: arial, helvetica, sans-serif; } #content { font-family: arial, helvetica, sans-serif; } #sidebar { font-family: arial, helvetica, sans-serif; } h1 { font-family: georgia, times, serif; }
  • 20. body { font-family: arial, helvetica, sans-serif; } h1 { font-family: georgia, times, serif; }
  • 21. 4 Use multiple selectors
  • 23. h1 { color: #236799; } h2 { color: #236799; } h3 { color: #236799; } h4 { color: #236799; }
  • 25. h1, h2, h3, h4 { color: #236799; }
  • 26. 5 Use multiple declarations
  • 28. p { margin: 0 0 1em; } p { background: #ddd; } p { color: #666; }
  • 30. p { margin: 0 0 1em; background: #ddd; color: #666; }
  • 31. 6 Use shorthand properties
  • 33. body { font-size : 85%; font-family : arial, helvetica, sans-serif; background-image : url(image.gif); background-repeat : no-repeat; background-position : 0 100%; margin-top : 1em; margin-right : 1em; margin-bottom : 0; margin-left : 1em; padding-top : 10px; padding-right : 10px; padding-bottom : 10px; padding-left : 10px; border-style : solid; border-width : 1px; border-color : red; color : #222222; }
  • 35. body { font : 85% arial, helvetica, sans-serif; background : url(image.gif) no-repeat 0 100%; margin : 1em 1em 0; padding : 10px; border : 1px solid red; color : #222; }
  • 37. Place a time stamp, author and notation at top of CSS files. 1
  • 38. /* --------------------------------- Site: Site name Author: Name Updated: Date and time Updated by: Name --------------------------------- */
  • 39. Include global color notation 2
  • 40. /* --------------------------------- COLORS Body background: #def455 Container background: #fff Main Text: #333 Links: #00600f Visited links: #098761 Hover links: #aaf433 H1, H2, H3: #960 H4, H5, H6: #000 --------------------------------- */
  • 41. Use meaningful names for IDs & classes 3
  • 43. .green-box { ... } #big-text { ... }
  • 45. .pullquote {... } #introduction {... }
  • 46. Group related rules 4
  • 47. #header { ... } #header h1 { ... } #header h1 img { ... } #header form { ... } #header a#skip { ... } #navigation { ... } #navigation ul { ... } #navigation ul li { ... } #navigation ul li a { ... } #navigation ul li a:hover { ... } #content { ... } #content h2 { ... } #content p { ... } #content ul { ... } #content ul li { ... }
  • 48. Add clear comments to your CSS files 5
  • 49. /* --------------------------------- header styles --------------------------------- */ #header { ... } #header h1 { ... } #header h1 img { ... } #header form { ... } /* --------------------------------- navigation styles --------------------------------- */ #navigation { ... }
  • 50. Modular CSS (to be continued…)