際際滷

際際滷Share a Scribd company logo
CSS Best practices & tips Jos辿 Teixid坦 - http://www.sargebig.com
The Approach Markup comes first   Content blocks (use #IDs) Then the actual content (cascade and/or .classes) CSS Styling Reset browser defaults Layout The "Inverted pyramid": General site wide styles first then exceptions and specifics油 Develop on FF but check on IE regularly! Validate   Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
The Markup Write beautiful & semantic code: 油 Consistent & meaningful naming. Hint:  redText  is NOT meaningful. Pick a  semantically  correct tag for each job Indent lines Comment, but watch your mouth! (it goes to the browser!) Avoid inline style & scripts As a rule of thumb every element in the in the DOM should have a meaningful, semantic & content supporting existence. Hint: No  empty <div>  or  <br clear=&quot;all&quot;>   油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Semantics For accessibility, easy of maintenance, SEO and  good karma 油 Use header tags  <h1>  to  <h6>  where appropiate If it is a list of something, it should be a  <ul>  or a  <ol> Use  <em>  instead of  <i> , and  <strong>  instead of  <b> Tables are dead, long live the  <table> ... but not for layout,  not even to format forms! . Use  <fieldset>  and  <label> If it is only for aesthetics it probably doesn't  belong to the DOM 油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Markup comments Navigating the code 油 油油 油 <div id=&quot; content &quot;> 油油 油油油 油 <div id=&quot; story &quot;> 油油 油油油 油油油 油 3000 lines of code... 油油油 油油油 </div> <!-- end of # story  --> 油油 油油油油  10 other nested divs...   油油油 </div> <!-- end of # content  --> 油油 油 in 3 different PHP/ASP/JSP files...   油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
The CSS reset For consistency & easier debugging  油 Blanks browser default formatting (because they all see the world in their unique  &quot;wonderful&quot;  way) Pick your flavour:油 Universal * reset油  Meyer reset  YUI reset Or create your own!  Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Fonts For consistency & easier debugging  油 Size'em with  em  instead of  px  whenever possible Use Richard Rutter's  62.5% trick  for predictable sizing Don't replace text with an <img> element, instead:油 Use the  Mike Rundle`s method  for an unobtrusive background image replacement, or Use Shaun Inman's  sIFR technique Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Images Freshly minced flavor for your site 油 Try to avoid transparencies, if not possible try to cheat it with GIF, if not possible... PNG +  AlphaImageLoader   but  no bg repeats or positioning, some links won't work and if you play it backwards you listen weird voices, it is just evil Combine small graphics in  CSS sprites 油  Preload sprites for performance Better in tall and thin aspect ratio Don't resize images through CSS Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Targeting IE Conditional style sheets 油 <link rel=&quot;stylesheet&quot; href=&quot;main.css&quot; type=&quot;text/css&quot; /> 油 <!--[if IE 6]><link rel=&quot;stylesheet&quot; href=&quot;main-ie6.css&quot; type=&quot;text/css&quot; /><![endif]-->  油 Pro: Great way to avoid CSS Hacks Con: Two (or more) css files to maintain, usually just because of model box related tweaks Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Targeting IE Conditional tagging 油 <!--[if !IE]>--><body><!--<![endif]-->  <!--[if IE 6]><body class=&quot;ie6&quot;><![endif]-->  油 Pro: Great way to avoid CSS Hacks & multiple sheets Con: Heavier to parse for non-IE browsers, so don't go crazy with it. Will contaminate your beautiful code! Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
Links 油 Use common sense and a lot of contrast Use the  L o V e  H A te order when syling links: a: link { ... } a: visited { ... } a: hover { ... } a: active { ... }油 Try to enlarge clickable areas for smaller text links  Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
CSS for debugging Using style as markup anti-pesto  油 Advanced CSS selectors can be used to isolate offending tags in the markup Just create a debug.css file and define some styles addressing links with empty hrefs, no alt on images, inline style, etc You can import this file when you think you are done with your markup / layout and just take it off before it goes live (once you took care of those bugs!) Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
CSS for debugging Finding images with missing attrs  油 油油 油 img[alt=&quot;&quot;] {border: 3px solid orange;}油油 油油 油油 油 img[title=&quot;&quot;] {outline: 3px solid orange;}油油 油 油油 油 img:not([alt]) {border: 5px solid orange;}油油 油 油油 油 img:not([title]) {outline: 5px solid orange;} Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
CSS for debugging Finding links with missing hrefs  油油 油 a[href=&quot;#&quot;] {background: orange;}油油油 油 油油 油 a[href=&quot;&quot;] {background: orange;} Finding header hierarchy  油油油  h1 {background: red;} 油油 油 h2 {background: orange;} 油油 油 h3 {background: yellow;}油  油   Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
CSS for debugging Using outline instead of border 油油油  .element-to-debug { outline : 1px solid red;} 油油油  油 Note: outline as opposed to border doesn't add space to the element, thus won't break anything in your layout. However, since it is not fully supported we can only use it for debug 油   Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
That's all! Hope you enjoyed it!

More Related Content

What's hot (20)

Basic HTML
Basic HTMLBasic HTML
Basic HTML
sunmitraeducation
Designing Firefox Themes
Designing Firefox ThemesDesigning Firefox Themes
Designing Firefox Themes
Lim Chee Aun
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
Frontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser renderingFrontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser rendering
Manuel Garcia
Google Sites Web Page Creation
Google Sites Web Page CreationGoogle Sites Web Page Creation
Google Sites Web Page Creation
Brian Stumbaugh
CSS_GUIDE_Intro
CSS_GUIDE_IntroCSS_GUIDE_Intro
CSS_GUIDE_Intro
tutorialsruby
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS Workshop
Shay Howe
Web design for right-to-left languages
Web design for right-to-left languagesWeb design for right-to-left languages
Web design for right-to-left languages
Lennart Schoors
Juggling
JugglingJuggling
Juggling
Ross Lawley
HTML CSS and Web Development
HTML CSS and Web DevelopmentHTML CSS and Web Development
HTML CSS and Web Development
Rahul Mishra
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
Dalibor Gogic
HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners
Nimrakhan89
Html in a box
Html in a boxHtml in a box
Html in a box
bdubuque
Modular HTML & CSS Workshop
Modular HTML & CSS WorkshopModular HTML & CSS Workshop
Modular HTML & CSS Workshop
Shay Howe
Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3
Todd Zaki Warfel
Slicing the web
Slicing the webSlicing the web
Slicing the web
Mohamad Hemmat
Haml, Sass and Compass for Sane Web Development
Haml, Sass and Compass for Sane Web DevelopmentHaml, Sass and Compass for Sane Web Development
Haml, Sass and Compass for Sane Web Development
jeremyw
Yerma
YermaYerma
Yerma
kiarita305
HTML+CSS: how to get started
HTML+CSS: how to get startedHTML+CSS: how to get started
HTML+CSS: how to get started
Dimitris Tsironis
Web Design 101
Web Design 101Web Design 101
Web Design 101
vegdwk
Designing Firefox Themes
Designing Firefox ThemesDesigning Firefox Themes
Designing Firefox Themes
Lim Chee Aun
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
Frontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser renderingFrontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser rendering
Manuel Garcia
Google Sites Web Page Creation
Google Sites Web Page CreationGoogle Sites Web Page Creation
Google Sites Web Page Creation
Brian Stumbaugh
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS Workshop
Shay Howe
Web design for right-to-left languages
Web design for right-to-left languagesWeb design for right-to-left languages
Web design for right-to-left languages
Lennart Schoors
HTML CSS and Web Development
HTML CSS and Web DevelopmentHTML CSS and Web Development
HTML CSS and Web Development
Rahul Mishra
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
Dalibor Gogic
HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners
Nimrakhan89
Html in a box
Html in a boxHtml in a box
Html in a box
bdubuque
Modular HTML & CSS Workshop
Modular HTML & CSS WorkshopModular HTML & CSS Workshop
Modular HTML & CSS Workshop
Shay Howe
Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3
Todd Zaki Warfel
Haml, Sass and Compass for Sane Web Development
Haml, Sass and Compass for Sane Web DevelopmentHaml, Sass and Compass for Sane Web Development
Haml, Sass and Compass for Sane Web Development
jeremyw
HTML+CSS: how to get started
HTML+CSS: how to get startedHTML+CSS: how to get started
HTML+CSS: how to get started
Dimitris Tsironis
Web Design 101
Web Design 101Web Design 101
Web Design 101
vegdwk

Similar to CSS Best practices (20)

Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
Gareth Saunders
WordPress Development Confoo 2010
WordPress Development Confoo 2010WordPress Development Confoo 2010
WordPress Development Confoo 2010
Brendan Sera-Shriar
Css
CssCss
Css
MAGNA COLLEGE OF ENGINEERING
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
joshpuckett
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
joshpuckett
CSS
CSSCSS
CSS
anandha ganesh
Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
Felipe Lav鱈n
3 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 202101053 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 20210105
John Picasso
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
Hatem Mahmoud
Css Best Practices
Css Best PracticesCss Best Practices
Css Best Practices
sachin9737
Css Best Practices
Css Best PracticesCss Best Practices
Css Best Practices
guest3ebcca
Xhtml Css Presentation
Xhtml Css PresentationXhtml Css Presentation
Xhtml Css Presentation
joshpuckett
Visualforce css developer guide(by forcetree.com)
Visualforce css developer guide(by forcetree.com)Visualforce css developer guide(by forcetree.com)
Visualforce css developer guide(by forcetree.com)
Edwin Vijay R
css.ppt
css.pptcss.ppt
css.ppt
Sana903754
css.ppt
css.pptcss.ppt
css.ppt
DakshPratapSingh1
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
raghavanp4
Doing More with LESS for CSS
Doing More with LESS for CSSDoing More with LESS for CSS
Doing More with LESS for CSS
Todd Anglin
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
Francesco Fullone
Advance Css
Advance CssAdvance Css
Advance Css
vijayta
Advance Css 1194323118268797 5
Advance Css 1194323118268797 5Advance Css 1194323118268797 5
Advance Css 1194323118268797 5
dharshyamal
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
Gareth Saunders
WordPress Development Confoo 2010
WordPress Development Confoo 2010WordPress Development Confoo 2010
WordPress Development Confoo 2010
Brendan Sera-Shriar
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
joshpuckett
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
joshpuckett
Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
Felipe Lav鱈n
3 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 202101053 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 20210105
John Picasso
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
Hatem Mahmoud
Css Best Practices
Css Best PracticesCss Best Practices
Css Best Practices
sachin9737
Css Best Practices
Css Best PracticesCss Best Practices
Css Best Practices
guest3ebcca
Xhtml Css Presentation
Xhtml Css PresentationXhtml Css Presentation
Xhtml Css Presentation
joshpuckett
Visualforce css developer guide(by forcetree.com)
Visualforce css developer guide(by forcetree.com)Visualforce css developer guide(by forcetree.com)
Visualforce css developer guide(by forcetree.com)
Edwin Vijay R
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
raghavanp4
Doing More with LESS for CSS
Doing More with LESS for CSSDoing More with LESS for CSS
Doing More with LESS for CSS
Todd Anglin
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
Francesco Fullone
Advance Css
Advance CssAdvance Css
Advance Css
vijayta
Advance Css 1194323118268797 5
Advance Css 1194323118268797 5Advance Css 1194323118268797 5
Advance Css 1194323118268797 5
dharshyamal

Recently uploaded (20)

Transform your space into a sanctuary with SPL Interiors where comfort meet...
Transform your space into a sanctuary with SPL Interiors  where comfort meet...Transform your space into a sanctuary with SPL Interiors  where comfort meet...
Transform your space into a sanctuary with SPL Interiors where comfort meet...
SPL Interiors
APPROPRIATETECHNOLOGIES FOR URBAN AND RURAL HOUSING
APPROPRIATETECHNOLOGIES FOR URBAN AND  RURAL HOUSINGAPPROPRIATETECHNOLOGIES FOR URBAN AND  RURAL HOUSING
APPROPRIATETECHNOLOGIES FOR URBAN AND RURAL HOUSING
JIT KUMAR GUPTA
Classroom Management that will tmotivate
Classroom Management that will tmotivateClassroom Management that will tmotivate
Classroom Management that will tmotivate
SherifsStorytime
Introductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptxIntroductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptx
khaledsameh950
Design I.Y. HOUSING at Lonavala by S+PS Architects, Sublime Ordinariness H...
Design I.Y. HOUSING at Lonavala by   S+PS Architects,  Sublime Ordinariness H...Design I.Y. HOUSING at Lonavala by   S+PS Architects,  Sublime Ordinariness H...
Design I.Y. HOUSING at Lonavala by S+PS Architects, Sublime Ordinariness H...
JnaneshPreethan
If I Miss This Putt I'll Kill Myself Shirt
If I Miss This Putt I'll Kill Myself ShirtIf I Miss This Putt I'll Kill Myself Shirt
If I Miss This Putt I'll Kill Myself Shirt
TeeFusion
Nitro Pro Crack Enterprise Free Download
Nitro Pro Crack Enterprise Free DownloadNitro Pro Crack Enterprise Free Download
Nitro Pro Crack Enterprise Free Download
kortez3
Ramadhan 3 Fancy.pdfRamadhan 3 Fancy.pdf
Ramadhan 3 Fancy.pdfRamadhan 3 Fancy.pdfRamadhan 3 Fancy.pdfRamadhan 3 Fancy.pdf
Ramadhan 3 Fancy.pdfRamadhan 3 Fancy.pdf
SuryaDharma65
Ramadhan 1 Large.pdfRamadhan 1 Large.pdf
Ramadhan 1 Large.pdfRamadhan 1 Large.pdfRamadhan 1 Large.pdfRamadhan 1 Large.pdf
Ramadhan 1 Large.pdfRamadhan 1 Large.pdf
SuryaDharma65
Tarma - Chanchamayo diagrama unifilar.pdf
Tarma - Chanchamayo diagrama unifilar.pdfTarma - Chanchamayo diagrama unifilar.pdf
Tarma - Chanchamayo diagrama unifilar.pdf
Roger Roman
Sacrament of Confirmation& HolySpirit.pptx
Sacrament of Confirmation& HolySpirit.pptxSacrament of Confirmation& HolySpirit.pptx
Sacrament of Confirmation& HolySpirit.pptx
ShayneMcst
water_cycle.ppt vishana ppt 55555566666
water_cycle.ppt vishana ppt 55555566666water_cycle.ppt vishana ppt 55555566666
water_cycle.ppt vishana ppt 55555566666
patelvishana99
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
Ramadhan 4 Fancy.pdfRamadhan 4 Fancy.pdf
Ramadhan 4 Fancy.pdfRamadhan 4 Fancy.pdfRamadhan 4 Fancy.pdfRamadhan 4 Fancy.pdf
Ramadhan 4 Fancy.pdfRamadhan 4 Fancy.pdf
SuryaDharma65
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
Human-Centered Web3 Design: UNIPAWS Portfolio 2025
Human-Centered Web3 Design: UNIPAWS Portfolio 2025Human-Centered Web3 Design: UNIPAWS Portfolio 2025
Human-Centered Web3 Design: UNIPAWS Portfolio 2025
SannhetenFox
If I Miss This Putt I'll Kill Myself Hat
If I Miss This Putt I'll Kill Myself HatIf I Miss This Putt I'll Kill Myself Hat
If I Miss This Putt I'll Kill Myself Hat
TeeFusion
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
RESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptx
RESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptxRESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptx
RESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptx
AnalycaSibul
Smart Farming Technology Pitch Deck Presentation Template
Smart Farming Technology Pitch Deck Presentation TemplateSmart Farming Technology Pitch Deck Presentation Template
Smart Farming Technology Pitch Deck Presentation Template
際際滷sBrain
Transform your space into a sanctuary with SPL Interiors where comfort meet...
Transform your space into a sanctuary with SPL Interiors  where comfort meet...Transform your space into a sanctuary with SPL Interiors  where comfort meet...
Transform your space into a sanctuary with SPL Interiors where comfort meet...
SPL Interiors
APPROPRIATETECHNOLOGIES FOR URBAN AND RURAL HOUSING
APPROPRIATETECHNOLOGIES FOR URBAN AND  RURAL HOUSINGAPPROPRIATETECHNOLOGIES FOR URBAN AND  RURAL HOUSING
APPROPRIATETECHNOLOGIES FOR URBAN AND RURAL HOUSING
JIT KUMAR GUPTA
Classroom Management that will tmotivate
Classroom Management that will tmotivateClassroom Management that will tmotivate
Classroom Management that will tmotivate
SherifsStorytime
Introductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptxIntroductory f 23233224242342455Lec..pptx
Introductory f 23233224242342455Lec..pptx
khaledsameh950
Design I.Y. HOUSING at Lonavala by S+PS Architects, Sublime Ordinariness H...
Design I.Y. HOUSING at Lonavala by   S+PS Architects,  Sublime Ordinariness H...Design I.Y. HOUSING at Lonavala by   S+PS Architects,  Sublime Ordinariness H...
Design I.Y. HOUSING at Lonavala by S+PS Architects, Sublime Ordinariness H...
JnaneshPreethan
If I Miss This Putt I'll Kill Myself Shirt
If I Miss This Putt I'll Kill Myself ShirtIf I Miss This Putt I'll Kill Myself Shirt
If I Miss This Putt I'll Kill Myself Shirt
TeeFusion
Nitro Pro Crack Enterprise Free Download
Nitro Pro Crack Enterprise Free DownloadNitro Pro Crack Enterprise Free Download
Nitro Pro Crack Enterprise Free Download
kortez3
Ramadhan 3 Fancy.pdfRamadhan 3 Fancy.pdf
Ramadhan 3 Fancy.pdfRamadhan 3 Fancy.pdfRamadhan 3 Fancy.pdfRamadhan 3 Fancy.pdf
Ramadhan 3 Fancy.pdfRamadhan 3 Fancy.pdf
SuryaDharma65
Ramadhan 1 Large.pdfRamadhan 1 Large.pdf
Ramadhan 1 Large.pdfRamadhan 1 Large.pdfRamadhan 1 Large.pdfRamadhan 1 Large.pdf
Ramadhan 1 Large.pdfRamadhan 1 Large.pdf
SuryaDharma65
Tarma - Chanchamayo diagrama unifilar.pdf
Tarma - Chanchamayo diagrama unifilar.pdfTarma - Chanchamayo diagrama unifilar.pdf
Tarma - Chanchamayo diagrama unifilar.pdf
Roger Roman
Sacrament of Confirmation& HolySpirit.pptx
Sacrament of Confirmation& HolySpirit.pptxSacrament of Confirmation& HolySpirit.pptx
Sacrament of Confirmation& HolySpirit.pptx
ShayneMcst
water_cycle.ppt vishana ppt 55555566666
water_cycle.ppt vishana ppt 55555566666water_cycle.ppt vishana ppt 55555566666
water_cycle.ppt vishana ppt 55555566666
patelvishana99
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
Ramadhan 4 Fancy.pdfRamadhan 4 Fancy.pdf
Ramadhan 4 Fancy.pdfRamadhan 4 Fancy.pdfRamadhan 4 Fancy.pdfRamadhan 4 Fancy.pdf
Ramadhan 4 Fancy.pdfRamadhan 4 Fancy.pdf
SuryaDharma65
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
Human-Centered Web3 Design: UNIPAWS Portfolio 2025
Human-Centered Web3 Design: UNIPAWS Portfolio 2025Human-Centered Web3 Design: UNIPAWS Portfolio 2025
Human-Centered Web3 Design: UNIPAWS Portfolio 2025
SannhetenFox
If I Miss This Putt I'll Kill Myself Hat
If I Miss This Putt I'll Kill Myself HatIf I Miss This Putt I'll Kill Myself Hat
If I Miss This Putt I'll Kill Myself Hat
TeeFusion
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
RESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptx
RESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptxRESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptx
RESPONSIBILITIESPPT2 (PE & HEALTH).pptx.pptx
AnalycaSibul
Smart Farming Technology Pitch Deck Presentation Template
Smart Farming Technology Pitch Deck Presentation TemplateSmart Farming Technology Pitch Deck Presentation Template
Smart Farming Technology Pitch Deck Presentation Template
際際滷sBrain

CSS Best practices

  • 1. CSS Best practices & tips Jos辿 Teixid坦 - http://www.sargebig.com
  • 2. The Approach Markup comes first Content blocks (use #IDs) Then the actual content (cascade and/or .classes) CSS Styling Reset browser defaults Layout The &quot;Inverted pyramid&quot;: General site wide styles first then exceptions and specifics油 Develop on FF but check on IE regularly! Validate Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 3. The Markup Write beautiful & semantic code: 油 Consistent & meaningful naming. Hint: redText is NOT meaningful. Pick a semantically correct tag for each job Indent lines Comment, but watch your mouth! (it goes to the browser!) Avoid inline style & scripts As a rule of thumb every element in the in the DOM should have a meaningful, semantic & content supporting existence. Hint: No empty <div> or <br clear=&quot;all&quot;> 油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 4. Semantics For accessibility, easy of maintenance, SEO and good karma 油 Use header tags <h1> to <h6> where appropiate If it is a list of something, it should be a <ul> or a <ol> Use <em> instead of <i> , and <strong> instead of <b> Tables are dead, long live the <table> ... but not for layout, not even to format forms! . Use <fieldset> and <label> If it is only for aesthetics it probably doesn't belong to the DOM 油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 5. Markup comments Navigating the code 油 油油 油 <div id=&quot; content &quot;> 油油 油油油 油 <div id=&quot; story &quot;> 油油 油油油 油油油 油 3000 lines of code... 油油油 油油油 </div> <!-- end of # story --> 油油 油油油油 10 other nested divs... 油油油 </div> <!-- end of # content --> 油油 油 in 3 different PHP/ASP/JSP files... 油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 6. The CSS reset For consistency & easier debugging 油 Blanks browser default formatting (because they all see the world in their unique &quot;wonderful&quot; way) Pick your flavour:油 Universal * reset油 Meyer reset YUI reset Or create your own! Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 7. Fonts For consistency & easier debugging 油 Size'em with em instead of px whenever possible Use Richard Rutter's 62.5% trick for predictable sizing Don't replace text with an <img> element, instead:油 Use the Mike Rundle`s method for an unobtrusive background image replacement, or Use Shaun Inman's sIFR technique Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 8. Images Freshly minced flavor for your site 油 Try to avoid transparencies, if not possible try to cheat it with GIF, if not possible... PNG + AlphaImageLoader but no bg repeats or positioning, some links won't work and if you play it backwards you listen weird voices, it is just evil Combine small graphics in CSS sprites 油 Preload sprites for performance Better in tall and thin aspect ratio Don't resize images through CSS Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 9. Targeting IE Conditional style sheets 油 <link rel=&quot;stylesheet&quot; href=&quot;main.css&quot; type=&quot;text/css&quot; /> 油 <!--[if IE 6]><link rel=&quot;stylesheet&quot; href=&quot;main-ie6.css&quot; type=&quot;text/css&quot; /><![endif]--> 油 Pro: Great way to avoid CSS Hacks Con: Two (or more) css files to maintain, usually just because of model box related tweaks Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 10. Targeting IE Conditional tagging 油 <!--[if !IE]>--><body><!--<![endif]--> <!--[if IE 6]><body class=&quot;ie6&quot;><![endif]--> 油 Pro: Great way to avoid CSS Hacks & multiple sheets Con: Heavier to parse for non-IE browsers, so don't go crazy with it. Will contaminate your beautiful code! Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 11. Links 油 Use common sense and a lot of contrast Use the L o V e H A te order when syling links: a: link { ... } a: visited { ... } a: hover { ... } a: active { ... }油 Try to enlarge clickable areas for smaller text links Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 12. CSS for debugging Using style as markup anti-pesto 油 Advanced CSS selectors can be used to isolate offending tags in the markup Just create a debug.css file and define some styles addressing links with empty hrefs, no alt on images, inline style, etc You can import this file when you think you are done with your markup / layout and just take it off before it goes live (once you took care of those bugs!) Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 13. CSS for debugging Finding images with missing attrs 油 油油 油 img[alt=&quot;&quot;] {border: 3px solid orange;}油油 油油 油油 油 img[title=&quot;&quot;] {outline: 3px solid orange;}油油 油 油油 油 img:not([alt]) {border: 5px solid orange;}油油 油 油油 油 img:not([title]) {outline: 5px solid orange;} Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 14. CSS for debugging Finding links with missing hrefs 油油 油 a[href=&quot;#&quot;] {background: orange;}油油油 油 油油 油 a[href=&quot;&quot;] {background: orange;} Finding header hierarchy 油油油 h1 {background: red;} 油油 油 h2 {background: orange;} 油油 油 h3 {background: yellow;}油 油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 15. CSS for debugging Using outline instead of border 油油油 .element-to-debug { outline : 1px solid red;} 油油油 油 Note: outline as opposed to border doesn't add space to the element, thus won't break anything in your layout. However, since it is not fully supported we can only use it for debug 油 Jos辿 Teixid坦 - http://www.sargebig.com CSS Best Practices & tips
  • 16. That's all! Hope you enjoyed it!