SlideShare a Scribd company logo
Cascading Style Sheets Hatem Mahmoud [email_address]
Part 2
Quick Review
I don't hate Microsoft
What is CSS? Layers of a web page: Content: Text, images, videos, etc. Presentation: How the content will appear to a human Behavior: Real-time user interaction: validation, sorting, drag-n-drop, etc.
What is CSS? CSS separates the presentation from the content
Why CSS? Flexible, can be applied in several ways Easy to maintain Accessibility to different users with different devices.  CSS caching = less bandwidth + fast loading
Need for Guidelines
Why Guidelines? Stability Cross-browser compatibility Consistency Readability Maintainability More time for real development
How?
1) Establish a set of rules
2) Document those rules
3) Enforce their use
Thank You!
wait
General Guidelines
Respect major browsers IE 6+ Firefox 2+ Safari 3+
Major Browsers (6, 2008) Source: http://www.w3schools.com/browsers/
Don't ignore IE 6
IE7.js A JavaScript library to make Microsoft Internet Explorer (5, 6, 7) behave like a standards-compliant browser. http://code.google.com/p/ie7-js/
IE7.js
IE7.js Hot Link <!--[if lt IE 7]> <script type=&quot;text/javascript&quot; src=&quot; http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js &quot; > </script> <![endif]-->
Use semantic markup
Semantic Markup HTML is for describing the structure not the presentation of the content Use HTML elements for what they were made for: <div> ,  <span> ,  <label> ,  <p> ,  <br/> ,  <h2> ,  <th> ,  <td> ,  <ul> ,  <ol> ,  <li> , ... Don't nest blocks inside inline elements: <span><p> incorrect </p></span>
Do not use tables for layout, they were made for tabular data
 
 
Always use Web-safe fonts (Common fonts to all versions of Windows and Mac)
Web-safe fonts Arial Arial Black Comic Sans MS Courier New Georgia Impact Lucida Console Lucida Sans Unicode Tahoma Times New Roman Trebuchet MS Verdana
When possible, use transparent GIFs instead of transparent PNGs
Never resize images in CSS or HTML, they would look ugly
Make your site accessible and usable for all users and devices
Accessibility & Usability Provide a “Skip to Main Content” link Always provide a text equivalent for non-text content (image, video, flash, etc.) Differentiate links (underlined) and use meaningful names (avoid &quot;click here&quot;) Ensure that the color combinations have an adequate contrast Don't expect the user to use a mouse!
Validate your markup http://validator.w3.org/
Validate your CSS http://jigsaw.w3.org/css-validator/
CSS Guidelines
Avoid inline styles
Avoid inline styles Bad <p style=&quot; color:red;margin:0; &quot;>   My poor paragraph. </p> Good <link  href=&quot;screen.css&quot; media=&quot;screen&quot; rel=&quot;Stylesheet&quot; type=&quot;text/css&quot; />
Avoid fancy CSS3 selectors
Compress your CSS http://www.cssdrive.com/
Coding Tips
Coding Tips 1) File-naming convention: screen.css ,  ie6.css ,  reset.css , etc. 2) CSS rule names should describe the purpose not the style. Use:  #sidebar ,  .date , etc. Instead of:  #div1 ,  .red , etc.
Coding Tips 3) Divide into specific sections: /*--->>> GLOBAL <<<---*/ ... /*--->>> HEADER <<<---*/ ... /*--->>> FOOTER <<<---*/ ...
Coding Tips 4) Use indentation: #sidebar { width: 392px; }   #sidebar #articles { background: #ccc; } .side_button { background: #fff; }
Coding Tips 5) Use shorthand properties: div { margin: 10px } div { margin: 10px 3px } div { padding: 10px 5px 3px } div { padding: 10px 0 0 3px } div { border: 1px solid #000; } div { font: 140% Verdana; }
Coding Tips 6) Surround embedded styles, if needed, with HTML comment characters to hide from older browsers:  <head>   <!--   <style type=&quot;text/css&quot;>   h1 {color:blue;}   </style>   --> </head>
Organize your CSS
How?
Use a framework typography.css, grid.css, layout.css, form.css, etc.
 
Or design your own
Organize your CSS 1) Separate your CSS code: reset.css header.css content.css footer.css ie.css
Organize your CSS 2) Use a master CSS file: master.css @import url(”reset.css”); @import url(”header.css”); @import url(”content.css”); @import url(”footer.css”); @import url(”ie.css”);
Organize your CSS 3) Link to the master CSS file: template.html <link  href=&quot; master.css &quot; media=&quot;screen&quot; rel=&quot;Stylesheet&quot; type=&quot;text/css&quot; />
Why?
Master CSS Little code in each file One link to all CSS files Disable styling for some parts Add more CSS files without touching HTML files Separate hacks code
CSS Reset
CSS Reset * { margin:0; padding:0; } 1) Eliminates all differences in padding and  margin across browsers 2) Eliminates margin collapses But 1) Very heavy on the rendering agent to apply rules to every single element 2) Destroys a lot of good default styling
Solution?
Begin with a few default styles
CSS Reset body, form  { margin: 0; padding: 0; font-family: Verdana; } h1, h2, h3, p, ul, ol  { margin: 0 0 1em; }
CSS Reset img  { border: none; } table  { border-collapse: collapse; } input, select, textarea  { font-family: inherit; }
Keep a library of helpful classes
Helpful Classes .float_left  { float: left; } .float_right  { float: right; } .clear_both  { clear: both; }
Techniques
Avoid CSS Hacks!
Box Model Bug
Avoid The Bug Avoid specifying both  width  and  padding  or  border  for an element #sidebar {width:250px} #news {padding:10px; border:1px solid;} <div id=&quot;sidebar&quot;> <div id=&quot;news&quot;> News </div> </div>
IE Hacks Use IE Conditional Comments to link to a different CSS file: <!--[if IE 5]> <link href=&quot;ie5.css” type=&quot;text/css&quot;> <![endif]-->
IE Hacks [if IE] All versions of IE [if IE 6] Only version 6 [if lt IE 7] Less than 7 [if lte IE 7] Less than or equal to 7 [if gt IE 5] Greater than 5 [if gre IE 5] Greater than or equal to 5
Targeting different media types
<link type=&quot;text/css&quot; href=&quot;screen.css&quot; media=&quot; screen &quot; />
 
<link type=&quot;text/css&quot; href=&quot;print.css&quot; media=&quot; print &quot; />
 
Supported values: all ,  aural ,  braille ,  embossed ,  handheld ,  print ,  projection ,  screen ,  tty ,  tv
Default value:  all
Alternative Style Sheets
A document can link to multiple style sheets
You can give it a default style and any number of alternatives for the user to choose from
How to choose one?
Some browsers support it
Alternative Style Sheets
Some browsers don't ;)
How to create them?
Using the right  rel  and  title  attributes
1) Persistent style sheets
Linked  without  a  title  attribute and always applied
<link type=&quot;text/css&quot; href=&quot;main.css&quot; rel=&quot;stylesheet&quot; /> Persistent style sheets
Persistent style sheets
2) Preferred style sheets
Linked with a  title  attribute and selected by default
<link type=&quot;text/css&quot; href=&quot;green.css&quot; rel=&quot;stylesheet&quot; title=&quot; Green &quot;  /> Preferred style sheets
Preferred style sheets
3) Alternate style sheets
Linked with a  title  attribute, and the  rel  attribute should be set to “ alternate stylesheet “
<link type=&quot;text/css&quot; href=&quot;orange.css&quot; rel=&quot;alternate stylesheet&quot; title=&quot; Orange &quot;  /> Alternate style sheets
Alternate style sheets
Not cross-browser?
Use JavaScript
Alternative Style Sheets
Floating
Floating A floated box is positioned within the normal flow, then taken out of the flow and shifted to the left ( float:left ) or right ( float:right ) until its outer edge touches the edge of the containing block or the outer edge of another float.
Floating Floating an element converts it to a block Unlike boxes in the normal flow, the vertical margins of a floated box are not collapsed with the margins of boxes either above or below it.
Floating
Floating Content flows down the right side of a left-floated box and down the left side of a right-floated box. A floated box must have an explicit width via the  width  property or its intrinsic width (for replaced elements:  img ,  input ,  textarea , etc.)
Example
Floating <p> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is my paragraph. This is  my paragraph. This is my  paragraph. </p>
Floating
Overlapping
Floating A floated box can overlap boxes adjacent to it in the normal flow.
Floating <p> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is the first paragraph. </p> <p> This is the second paragraph. </p>
Unhappy?
Clear it!
Clearing <p> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is the first paragraph. </p> <p style=&quot; clear:right; &quot;> This is the second paragraph. </p>
OR
Clearing <p> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is the first paragraph. </p> < br  style=&quot; clear:right; &quot; /> <p> This is the second paragraph. </p>
Clearing
Still unhappy?
Clearing <p> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is the first paragraph. < br  style=&quot; clear:right; &quot; /> </p> <p> This is the second paragraph. </p>
Clearing
Or, better ...
Clearing <p style=&quot; overflow:auto; &quot;> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is the first paragraph. </p> <p> This is the second paragraph. </p>
Clearing
If you get scroll bars...
Clearing
Do this...
Clearing <p style=&quot; overflow:hidden; &quot;> <span style=&quot; float:right; &quot;> This span is floated right. </span> This is the first paragraph. </p> <p> This is the second paragraph. </p>
To get this...
Clearing
Still unhappy?
Play Solitaire!
Multiple floats
Multiple floats <p> <span style=&quot; float:right; &quot;> first span </span> <span style=&quot; float:right; &quot;> second span </span> This is my paragraph. </p>
Multiple floats
Clearing
Multiple floats <p> <span style=&quot; float:right; &quot;> first span. </span> <span style=&quot; clear:right;     float:right; &quot;> second span. </span> This is my paragraph. </p>
Multiple floats
Fonts
A browser can only display the fonts that are installed on its machine.
Fonts Include one of the generic font face keywords at the end of any font list: body{ font-family: Verdana, Arial, sans-serif ; }
Firefox bug!
Firefox resizes heading elements when you specify a font size for the container
Solution
Always specify font size for heading elements (h1, h2, .., h6)
Sizing heading elements H1 {font-size:24px} H2 {font-size:18px} H3 {font-size:15px} H4 {font-size:12px}
Form elements don't inherit font properties, enforce them to do so
Font inheritance body { font-size:  18px; font-family: Verdana; } input, select, textarea { font-size:  100%; font-family:  inherit ; }
Using em
What is em? Wikipedia: In metal type, the em was the height of the metal body from which the letter rises. (c in this illustration)
What is em? In typography, em is a unit of measurement, equals to the point size of the current font em is not related to a specific typeface, and thus is the same for all fonts at a given point size.
Why?
IE 6 will  not  allow readers to resize text that has been sized in pixels!
Using ems The default size for ‘medium’ text in all browsers is  16px Now, you should convert px sizes to em: 10px => 0.625em 16px => 1em 20px => 1.25em 24px => 1.5em ...
Still want to think in pixels?
Solution http://www.clagnut.com
Using ems 1)Reduce this size for the entire document: to 10px:  body {font-size:62.5%} ( 10 / 16 ) * 100 = 62.5 2)Think in pixels: 10px => 1em 12px => 1.2em 8px => 0.8em
But remember, em is relative
em is relative body  {font-size:62.5%} #footer  {font-size:1.2em} /*12px*/ #footer p  {font-size:1em}  /*12px*/ #footer h3 {font-size:1.5em} /*18px*/
Discussion
Example
Example <p> Lorem ipsum dolor sit ... </p> <ul id=&quot;navigation&quot;> <li class=&quot;left&quot;> <a href=&quot;/back&quot;> Back </a> </li> <li class=&quot;right&quot;> <a href=&quot;/next&quot;> Next </a> </li> </ul>
Example
Example .left { float: left; } .right { float: right; } #navigation { list-style-type: none; margin: 0; padding: 0.5em 0; border-top: 1px solid #666; }
Example
Example #navigation li a { display: block; width: 5em; color: #FFF; background-color: #036; padding: .2em 0; text-align: center; text-decoration: none; }
Example
Example ul#navigation li a:hover { color: #FFF; background-color: #69C; }
The End
References
References http://www.w3.org/ http://www.w3schools.com/ http://www.sitepoint.com/ http://css.maxdesign.com.au/ http://www.smashingmagazine.com/
Thank You! tadsessions.espace.com.eg Hatem Mahmoud [email_address]

More Related Content

PPT
How Cascading Style Sheets (CSS) Works
ODP
Cascading Style Sheets - Part 01
PPT
CSS Basics
PDF
Introduction to HTML and CSS
PPTX
PPTX
Introducing Cascading Style Sheets
How Cascading Style Sheets (CSS) Works
Cascading Style Sheets - Part 01
CSS Basics
Introduction to HTML and CSS
Introducing Cascading Style Sheets

What's hot (20)

PPTX
Beginners css tutorial for web designers
PPT
Html & CSS - Best practices 2-hour-workshop
PDF
Intro to CSS
PPTX
1 03 - CSS Introduction
PPTX
Css ppt
PPT
Cascading Style Sheet
PPT
CSS
PPT
Html Expression Web
PDF
HTML CSS Basics
PDF
Basic-CSS-tutorial
PPTX
Cascading style sheet
PPTX
Css Basics
PDF
Efficient, maintainable CSS
ODP
Introduction to css & its attributes with syntax
ODP
PPTX
Cascading style sheets (CSS)
PPTX
Cascading Style Sheet (CSS)
PPTX
Introduction to HTML and CSS
Beginners css tutorial for web designers
Html & CSS - Best practices 2-hour-workshop
Intro to CSS
1 03 - CSS Introduction
Css ppt
Cascading Style Sheet
CSS
Html Expression Web
HTML CSS Basics
Basic-CSS-tutorial
Cascading style sheet
Css Basics
Efficient, maintainable CSS
Introduction to css & its attributes with syntax
Cascading style sheets (CSS)
Cascading Style Sheet (CSS)
Introduction to HTML and CSS
Ad

Viewers also liked (20)

PDF
The Box Model
PPTX
Floating
PPTX
Understanding the flex layout
PDF
Intro to OOCSS Workshop
PPTX
Nested lists in HTML
PDF
CSS3 filterとtransformをtransition, animationでアニメーション
PDF
Dynamic CSS: Transforms, Transitions, and Animation Basics
PPTX
Css floats
PDF
Css positioning
PPT
Print CSS
PPTX
Css animation
PPTX
CSS Transitions, Transforms, Animations
PDF
CSS Layouting #4 : Float
PPT
Javascript by geetanjali
PPT
Html ppt
PDF
CSS Layouting #5 : Position
PDF
CSS Box Model
PDF
Css box model
PDF
CSS Layouting #3 : Box Model
PPT
Css Ppt
The Box Model
Floating
Understanding the flex layout
Intro to OOCSS Workshop
Nested lists in HTML
CSS3 filterとtransformをtransition, animationでアニメーション
Dynamic CSS: Transforms, Transitions, and Animation Basics
Css floats
Css positioning
Print CSS
Css animation
CSS Transitions, Transforms, Animations
CSS Layouting #4 : Float
Javascript by geetanjali
Html ppt
CSS Layouting #5 : Position
CSS Box Model
Css box model
CSS Layouting #3 : Box Model
Css Ppt
Ad

Similar to Cascading Style Sheets - Part 02 (20)

PPT
Basics Of Css And Some Common Mistakes
PPT
How do speed up web pages? CSS & HTML Tricks
PPT
CSS 101
ODP
Creating Web Sites with HTML and CSS
PDF
A complete html and css guidelines for beginners
PDF
Pemrograman Web 2 - CSS
PPT
Advance Css
PPT
Advance Css 1194323118268797 5
PPT
PPT
CSS Part I
PDF
GDI Seattle Intermediate HTML and CSS Class 1
ODP
HTML5, CSS, JavaScript Style guide and coding conventions
PPT
Using a CSS Framework
PPT
HTML & CSS Workshop Notes
ODP
Worry free web development
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
PPT
Css Best Practices
Basics Of Css And Some Common Mistakes
How do speed up web pages? CSS & HTML Tricks
CSS 101
Creating Web Sites with HTML and CSS
A complete html and css guidelines for beginners
Pemrograman Web 2 - CSS
Advance Css
Advance Css 1194323118268797 5
CSS Part I
GDI Seattle Intermediate HTML and CSS Class 1
HTML5, CSS, JavaScript Style guide and coding conventions
Using a CSS Framework
HTML & CSS Workshop Notes
Worry free web development
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Css Best Practices

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Machine learning based COVID-19 study performance prediction
PDF
A comparative analysis of optical character recognition models for extracting...
Spectroscopy.pptx food analysis technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Accuracy of neural networks in brain wave diagnosis of schizophrenia
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Univ-Connecticut-ChatGPT-Presentaion.pdf
cloud_computing_Infrastucture_as_cloud_p
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
1. Introduction to Computer Programming.pptx
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Assigned Numbers - 2025 - Bluetooth® Document
Machine learning based COVID-19 study performance prediction
A comparative analysis of optical character recognition models for extracting...

Cascading Style Sheets - Part 02