SlideShare a Scribd company logo
1 of 24
Download to read offline
by Mike Wilcox, June 2016
Dangerous CSS
CLUB AJAX
Inheritance vs Cascade
• Inheritance refers to to what the style of the element will be based on its parent
elements
• Adding font-family: Arial; will apply that sale to all elements of the page, unless the element
specifies its own, overridng style
Inheritance vs Cascade
• Cascade refers to what the style of the element will be based on the definitions
in (potentially) many places:
• Browser default styles
• User defined styles
• Author styles
• External file
• In the document, using a style element
• On an specific element, using the style sttribute
Specificity
• What is the background color of the following element?
<div id="content" class="myContent" custom="true" style="background: white;">
This is my content
</div>
div{ background: yellow; }
.myContent{ background: darkred; }
div:first-child-of-type{ background: blue; }
#content{ background: black; }
div[custom="true"]{ background: orange; }
1
2
3
4
5
6
https://css-tricks.com/specifics-on-css-specificity/
Don’t Try These Things at Home…
Inline Styles
• Don’t: <div style=“width: 18px; color: #000;”>My Content</div>
• Breaks separation of concerns
• In frameworks, code must be rebuilt to see changes
• Specificity is way too high for general styling
Instead:
• All styles should go in a style sheet
BR
• Do not use <br> to increase the gap between lines of text
• it's not semantic. If you want two items, you probably want different elements
• It is an attempt at styling via markup
• Browsers will give different results
Instead:
• Use margins to separate elements
• Use <p> or <div> or other block styled element
&nbsp;
• In HTML, elements containing nothing but whitespace is considered empty and
have zero height
• An "empty" paragraph has zero height, so its vertical margins will collapse
• The space taken will depend on font size
Instead:
• Use padding to take up space
• Use margins to separate elements
IDs
• Styling IDs is overly specific
• IDs are unique, so the style cannot be reused
• NOTE: In JS frameworks, you shouldn’t be using IDs anyway
Instead:
• Use a className
Tables (for layout)
• Bad semantics
• Tables are for tabular data
• Often one table is not enough - nested tables are a nightmare
• a11y - Tables do not work well with screen readers
• Does not work well with RWD
Instead:
• Use best practices
Floats
• Designed to support magazine style layouts where text floats around the image
• Causes unwanted bugs or unpredictable side effects
Instead:
• Use inline-block, absolute positioning, or flex-box
Images
• Seriously, NO IMAGES!
• Images don’t scale
• Say goodbye to your image sprites
Instead:
• Use font icons or SVG
• SVG can be styled
Do These…
block vs inline vs inline-block
• inline has no dimensions. It takes the size of its contained text
• width, height, margin has no affect
• padding works since it is part of the contained text
• inline-block allows for dimensions
• By default, is the size of contained text
• supports vertical-align
• block allows for dimensions
• Creates a new line (don’t use <br>!!)
• Cannot be a child of a <p>
• By default, width is “auto”, sized to its container
• “auto” !== 100%
REM & EM
• px is a fixed width
• em is relative to its container size
• body{ font:10px} / body div{ font:0.5em} [5px] / body div div{ font:0.5em} [2.5px]
• rem is relative to root size
• body{ font:10px} / body div{ font:0.5em} [5px] / body div div{ font:0.5em} [5px]
• Use px for dimensions and borders
• Use a combination of em and rem for text, borders, and margins
• em works best for media queries
• Test all browsers - Safari is buggy
http://zellwk.com/blog/media-query-units/
flex-box
• The flexbox layout is direction-agnostic as opposed to the regular layouts: block
which is vertically-based and inline which is horizontally-based.
• Provides flexibility when it comes to orientation changing, resizing, stretching,
shrinking, etc.
• Not intuitive, and difficult to learn (but is worth the effort)
.container{
display: flex;
flex-flow: row wrap;
}
.item {
flex: 1 1 auto;
}
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
CSS Grid Layout (NA)
• The solution to layouts
• Works well with flex box
• The spec is still be worked on
.container{
grid-template-columns: 40px 50px auto 50px 40px;
grid-template-rows: 25% 100px auto;
}
https://css-tricks.com/snippets/css/complete-guide-grid/
Organizing
React Inline-styles
• Solves the “problem” of all CSS styles being global
• Is this a problem you even knew you had?
• This will be solved by the Shadow DOM
• Prevents CSS rot of large code bases
• Very likely a problem if you do not practice good modularity
• Already mixing HTML and JS, so, why not?
• While dynamic HTML adds to the spec, the same can not be said for CSS
where functionality such as cascading, inheritance, and reusability is removed
or reduced
Not so much condemning
this approach as much as
expressing concern with
introducing it to our stack
LESS - @variables
@primary-color: #6a7280;
@bk: linear-gradient(to bottom, @transWhite, @trans);
@border: 1px solid @primary-color;
@border-alt: none;
.section{
border: @border-alt;
background: @bk;
}
LESS - modularity
.widget{
&:focus{
border: 1px solid blue;
}
&.collapsed{
height: 0;
}
.title{
font-weight: bold;
.closeBtn{
.abs-right;
}
}
}
.widget{
display: block;
}
.widget:focus{
border: 1px solid blue;
}
.widget.collapsed{
height: 0;
}
.widget .title{
font-weight: bold;
}
.widget .title .closeBtn{
position: absolute;
right: 5px;
}
DEMOS
CLUB AJAX

More Related Content

What's hot

Week01 jan19 introductionto_php
Week01 jan19 introductionto_phpWeek01 jan19 introductionto_php
Week01 jan19 introductionto_php
Jeanho Chu
 

What's hot (20)

DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane EcosystemDownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
 
A journey from sass to css in-js
A journey from sass to css in-jsA journey from sass to css in-js
A journey from sass to css in-js
 
The Characteristics of a Successful SPA
The Characteristics of a Successful SPAThe Characteristics of a Successful SPA
The Characteristics of a Successful SPA
 
2010 11 pubcon_hendison-hosting
2010 11 pubcon_hendison-hosting2010 11 pubcon_hendison-hosting
2010 11 pubcon_hendison-hosting
 
The WordPress Way
The WordPress WayThe WordPress Way
The WordPress Way
 
Week01 jan19 introductionto_php
Week01 jan19 introductionto_phpWeek01 jan19 introductionto_php
Week01 jan19 introductionto_php
 
CSS Grid
CSS GridCSS Grid
CSS Grid
 
WordPress Theme Reviewers Team
WordPress Theme Reviewers TeamWordPress Theme Reviewers Team
WordPress Theme Reviewers Team
 
Best Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress MultisiteBest Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress Multisite
 
WordPress Setup and Security - WordCamp, Charleston 2014
WordPress Setup and Security - WordCamp, Charleston 2014WordPress Setup and Security - WordCamp, Charleston 2014
WordPress Setup and Security - WordCamp, Charleston 2014
 
Making Multisite Work for You
Making Multisite Work for YouMaking Multisite Work for You
Making Multisite Work for You
 
ClubAJAX Basics - Server Communication
ClubAJAX Basics - Server CommunicationClubAJAX Basics - Server Communication
ClubAJAX Basics - Server Communication
 
How does the Internet Work?
How does the Internet Work?How does the Internet Work?
How does the Internet Work?
 
Best Practices for Building Sites in dotCMS
Best Practices for Building Sites in dotCMSBest Practices for Building Sites in dotCMS
Best Practices for Building Sites in dotCMS
 
The web context
The web contextThe web context
The web context
 
Debugging WordPress
Debugging WordPressDebugging WordPress
Debugging WordPress
 
Isomorphic WordPress Applications with NodeifyWP
Isomorphic WordPress Applications with NodeifyWPIsomorphic WordPress Applications with NodeifyWP
Isomorphic WordPress Applications with NodeifyWP
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
 
WordPress Themes and Plugins
WordPress Themes and PluginsWordPress Themes and Plugins
WordPress Themes and Plugins
 
How to Build a Bespoke Page Builder in WordPress
How to Build a Bespoke Page Builder in WordPressHow to Build a Bespoke Page Builder in WordPress
How to Build a Bespoke Page Builder in WordPress
 

Similar to Dangerous CSS

Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
Peter Kaizer
 

Similar to Dangerous CSS (20)

ADF - Layout Managers and Skinning
ADF - Layout Managers and SkinningADF - Layout Managers and Skinning
ADF - Layout Managers and Skinning
 
CSS workshop @ OutSystems
CSS workshop @ OutSystemsCSS workshop @ OutSystems
CSS workshop @ OutSystems
 
Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
 
What is-sass-by-lucas-castro
What is-sass-by-lucas-castroWhat is-sass-by-lucas-castro
What is-sass-by-lucas-castro
 
Unit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxUnit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptx
 
CSS Framework + Progressive Enhacements
CSS Framework + Progressive EnhacementsCSS Framework + Progressive Enhacements
CSS Framework + Progressive Enhacements
 
WordPress Theming Best Practices
WordPress Theming Best PracticesWordPress Theming Best Practices
WordPress Theming Best Practices
 
The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
Css
CssCss
Css
 
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and Beyond
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS Troubleshooting
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
 
Css
CssCss
Css
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Introduction to Responsive Web Development
Introduction to Responsive Web DevelopmentIntroduction to Responsive Web Development
Introduction to Responsive Web Development
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
 
Css
CssCss
Css
 
Journey To The Front End World - Part2 - The Cosmetic
Journey To The Front End World - Part2 - The  CosmeticJourney To The Front End World - Part2 - The  Cosmetic
Journey To The Front End World - Part2 - The Cosmetic
 

More from Mike Wilcox

Webpage Design Basics for Non-Designers
Webpage Design Basics for Non-DesignersWebpage Design Basics for Non-Designers
Webpage Design Basics for Non-Designers
Mike Wilcox
 

More from Mike Wilcox (20)

Accessibility for Fun and Profit
Accessibility for Fun and ProfitAccessibility for Fun and Profit
Accessibility for Fun and Profit
 
WTF R PWAs?
WTF R PWAs?WTF R PWAs?
WTF R PWAs?
 
Advanced React
Advanced ReactAdvanced React
Advanced React
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Model View Madness
Model View MadnessModel View Madness
Model View Madness
 
Hardcore JavaScript – Write it Right
Hardcore JavaScript – Write it RightHardcore JavaScript – Write it Right
Hardcore JavaScript – Write it Right
 
The Great Semicolon Debate
The Great Semicolon DebateThe Great Semicolon Debate
The Great Semicolon Debate
 
AMD - Why, What and How
AMD - Why, What and HowAMD - Why, What and How
AMD - Why, What and How
 
Dojo & HTML5
Dojo & HTML5Dojo & HTML5
Dojo & HTML5
 
Webpage Design Basics for Non-Designers
Webpage Design Basics for Non-DesignersWebpage Design Basics for Non-Designers
Webpage Design Basics for Non-Designers
 
Why You Need a Front End Developer
Why You Need a Front End DeveloperWhy You Need a Front End Developer
Why You Need a Front End Developer
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About REST
 
The Fight Over HTML5
The Fight Over HTML5The Fight Over HTML5
The Fight Over HTML5
 
The Fight Over HTML5
The Fight Over HTML5The Fight Over HTML5
The Fight Over HTML5
 
How to get a Job as a Front End Developer
How to get a Job as a Front End DeveloperHow to get a Job as a Front End Developer
How to get a Job as a Front End Developer
 
The History of HTML5
The History of HTML5The History of HTML5
The History of HTML5
 
Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?
 
Flash And Dom
Flash And DomFlash And Dom
Flash And Dom
 
The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Dangerous CSS

  • 1. by Mike Wilcox, June 2016 Dangerous CSS CLUB AJAX
  • 2.
  • 3. Inheritance vs Cascade • Inheritance refers to to what the style of the element will be based on its parent elements • Adding font-family: Arial; will apply that sale to all elements of the page, unless the element specifies its own, overridng style
  • 4. Inheritance vs Cascade • Cascade refers to what the style of the element will be based on the definitions in (potentially) many places: • Browser default styles • User defined styles • Author styles • External file • In the document, using a style element • On an specific element, using the style sttribute
  • 5. Specificity • What is the background color of the following element? <div id="content" class="myContent" custom="true" style="background: white;"> This is my content </div> div{ background: yellow; } .myContent{ background: darkred; } div:first-child-of-type{ background: blue; } #content{ background: black; } div[custom="true"]{ background: orange; } 1 2 3 4 5 6 https://css-tricks.com/specifics-on-css-specificity/
  • 6. Don’t Try These Things at Home…
  • 7. Inline Styles • Don’t: <div style=“width: 18px; color: #000;”>My Content</div> • Breaks separation of concerns • In frameworks, code must be rebuilt to see changes • Specificity is way too high for general styling Instead: • All styles should go in a style sheet
  • 8. BR • Do not use <br> to increase the gap between lines of text • it's not semantic. If you want two items, you probably want different elements • It is an attempt at styling via markup • Browsers will give different results Instead: • Use margins to separate elements • Use <p> or <div> or other block styled element
  • 9. &nbsp; • In HTML, elements containing nothing but whitespace is considered empty and have zero height • An "empty" paragraph has zero height, so its vertical margins will collapse • The space taken will depend on font size Instead: • Use padding to take up space • Use margins to separate elements
  • 10. IDs • Styling IDs is overly specific • IDs are unique, so the style cannot be reused • NOTE: In JS frameworks, you shouldn’t be using IDs anyway Instead: • Use a className
  • 11. Tables (for layout) • Bad semantics • Tables are for tabular data • Often one table is not enough - nested tables are a nightmare • a11y - Tables do not work well with screen readers • Does not work well with RWD Instead: • Use best practices
  • 12. Floats • Designed to support magazine style layouts where text floats around the image • Causes unwanted bugs or unpredictable side effects Instead: • Use inline-block, absolute positioning, or flex-box
  • 13. Images • Seriously, NO IMAGES! • Images don’t scale • Say goodbye to your image sprites Instead: • Use font icons or SVG • SVG can be styled
  • 15. block vs inline vs inline-block • inline has no dimensions. It takes the size of its contained text • width, height, margin has no affect • padding works since it is part of the contained text • inline-block allows for dimensions • By default, is the size of contained text • supports vertical-align • block allows for dimensions • Creates a new line (don’t use <br>!!) • Cannot be a child of a <p> • By default, width is “auto”, sized to its container • “auto” !== 100%
  • 16. REM & EM • px is a fixed width • em is relative to its container size • body{ font:10px} / body div{ font:0.5em} [5px] / body div div{ font:0.5em} [2.5px] • rem is relative to root size • body{ font:10px} / body div{ font:0.5em} [5px] / body div div{ font:0.5em} [5px] • Use px for dimensions and borders • Use a combination of em and rem for text, borders, and margins • em works best for media queries • Test all browsers - Safari is buggy http://zellwk.com/blog/media-query-units/
  • 17. flex-box • The flexbox layout is direction-agnostic as opposed to the regular layouts: block which is vertically-based and inline which is horizontally-based. • Provides flexibility when it comes to orientation changing, resizing, stretching, shrinking, etc. • Not intuitive, and difficult to learn (but is worth the effort) .container{ display: flex; flex-flow: row wrap; } .item { flex: 1 1 auto; } https://css-tricks.com/snippets/css/a-guide-to-flexbox/
  • 18. CSS Grid Layout (NA) • The solution to layouts • Works well with flex box • The spec is still be worked on .container{ grid-template-columns: 40px 50px auto 50px 40px; grid-template-rows: 25% 100px auto; } https://css-tricks.com/snippets/css/complete-guide-grid/
  • 20. React Inline-styles • Solves the “problem” of all CSS styles being global • Is this a problem you even knew you had? • This will be solved by the Shadow DOM • Prevents CSS rot of large code bases • Very likely a problem if you do not practice good modularity • Already mixing HTML and JS, so, why not? • While dynamic HTML adds to the spec, the same can not be said for CSS where functionality such as cascading, inheritance, and reusability is removed or reduced Not so much condemning this approach as much as expressing concern with introducing it to our stack
  • 21. LESS - @variables @primary-color: #6a7280; @bk: linear-gradient(to bottom, @transWhite, @trans); @border: 1px solid @primary-color; @border-alt: none; .section{ border: @border-alt; background: @bk; }
  • 22. LESS - modularity .widget{ &:focus{ border: 1px solid blue; } &.collapsed{ height: 0; } .title{ font-weight: bold; .closeBtn{ .abs-right; } } } .widget{ display: block; } .widget:focus{ border: 1px solid blue; } .widget.collapsed{ height: 0; } .widget .title{ font-weight: bold; } .widget .title .closeBtn{ position: absolute; right: 5px; }
  • 23. DEMOS