SlideShare a Scribd company logo
Lecture 2: CSS II SFDV2001 Web Development
The Box Model In CSS  every  element in your HTML file is contained within a rectangular box. There are four main components to this box: Content Margin Padding Border Additionally there a couple of background components:  background colour background image
Image source:  http://www.hicksdesign.co.uk/boxmodel/
The Box Model Margins are always transparent. Padding is the space between the content and  the border. Background colour and/or image extend throughout the box model to the border. If a style of border used has gaps in it (e.g. dashed), the background shows through those gaps. The background of the parent element shows through the margin area of the box.
Width The width set for an element is the width of the  content . Padding, border and margin are additional to this width. h1{ width: 300px; padding: 5px; border: solid 10px #ff69b4; margin: 10px; } Total width on page for this element = 350 pixels Unless your IE: IE implements the box model incorrectly.
 
IE 5 (Mac) Safari Firefox
Source:  http://en.wikipedia.org/wiki/Image:Box-model-bug.png
Solutions There are hacks to combat many of the flaws in IE’s CSS rendering. Most exploit other IE bugs to provide workarounds. The Box Model hack (by Tantek Çelik) width: 350px; voice-family:”\”}\””; voice-family: inherit; width: 300px; IE doesn’t see the second width specification.
Selectors Recap:  selector{ property: value; } There are many different kinds of selectors: Standard element selectors Contextual selectors Class selectors ID selectors Pseudoselectors
Element selectors H1{ color: #456678; } You can group selectors: H1, p, li{ color: #456678; }  You can affect any element using the universal ( * ) selector.
Contextual Selectors Allow you to affect elements based on their context. That is, their relationship to other elements. Descendant selectors Elements that are contained within other elements: ul li{   color: #456678; } ul li a{   color: #456678; }
Contextual Selectors Child Selectors Similar to descendant selectors but it target only a  direct  child of an element: p > em{   color: #456678; }
Contextual Selectors Adjacent sibling selectors H1 + p{ margin-left: 5%; } Affects an element that comes immediately after another. In the above example the first paragraph after a top-level heading will be indented.
Class and ID selectors You can’t always style every element you want to with the standard selectors available and some times you need to make your own. There are two kinds of “custom-made” selectors:  class  and  ID . Class is used for a style that you may wish to use multiple times in a  single  html file. ID is used for a style you wish to be unique in any  one  html file. You must set the class or ID in your HTML code.
Class and ID selectors IDs take care of unique structural elements: Class is used for elements that are used multiple times : Heading Navigation Footer
 
Class and ID selectors In your style sheet: Class p.question{ color: navy; } Or  .question{   color: navy; }
Class and ID selectors In your style sheet: ID Div#footer{ border-top: solid 1px #555555; font-size: smaller; } Or  #footer{ border-top: solid 1px #555555; font-size: smaller; }
Class and ID selectors Resist the temptation to make everything a class. Make sure your id and class names are descriptive. “navigation” is descriptive of the function of the selector rather than the style. “red” is descriptive of a style - styles change. If you can use a contextual selector or the like instead of a class or ID, do so.
Pseudoselectors Some things that you want to style in an html document are not possible to represent with standard element selectors because there is no element in your HTML document to represent them. Different link states - visited, unvisited etc. are good examples. Pseudoselectors enable you to identify these portions of elements. Pseudoselectors are identified in your CSS using a colon. a:link
Pseudoselectors - Anchors Pseudoselectors are most commonly used to influence different link states. a:link a:visited a:hover a:active In transitional code the equivalents are the  link ,  vlink  and  alink  attributes of body. In CSS you get an extra link state (hover) and you can influence any aspect of a links style, not just colour.
Pseudoselectors - Anchors a:link{ text-decoration: none; ... } a:visited{ color:#555555; ... } a:hover{ text-decoration: underline; } a:active{ color:#f6dc3b;   ... }
Pseudoselectors - Anchors Anchor pseudoselectors should appear in your CSS in the order: a  a:link a:visited a:hover a:active If you don't, they may not function as they should. Putting : link  last for example would override the : hover  and : active  states.
Other pseudoselectors There are other pseudoselectors, but they aren't as commonly used as those associated with anchors because of poor browser support. :focus :first-child :first-line :first-letter :before :after :first-line  and  :first-letter  are currently the only ones of this list that have any reasonable browser support.
Block-level and Inline elements In html there are block elements and inline elements. The distinction between the two is important for how they may be nested.  You know from transitional code that  <font>  tags only validate when used inside  <p>  tags. This is because  <font>  is an inline element and  <p>  is a block level element. Block-level elements can contain other block-level elements and inline elements. Inline elements can only contain content and other inline elements.
 
Block-Level and Inline in CSS CSS allows you to explicitly state if an element is block-level or inline. BUT! These have nothing to do with the structure of your HTML and will not change the rules of validation. The notions of block-level and inline in CSS are presentation concepts only. display: block; display: inline;
 
 
Recommended sites: Hicks Design Box Model diagram: http://www.hicksdesign.co.uk/3dboxmodel/ Interactive Box Model diagram: http://www.redmelon.net/tstme/box_model/ W3C's Box Model description: http://www.w3.org/TR/REC-CSS2/box.html Tantek Çelik's Box Model hack: http://tantek.com/CSS/Examples/boxmodelhack.html Further reading: Web Design in a Nutshell,  3rd Edition   by Jennifer Niederst Robbins
Ad

Recommended

Lecture 9 Professional Practices
Lecture 9 Professional Practices
Sur College of Applied Sciences
 
Lecture1 B Frames&Forms
Lecture1 B Frames&Forms
Sur College of Applied Sciences
 
Lecture 9 Accessibility Original
Lecture 9 Accessibility Original
Sur College of Applied Sciences
 
Lecture 6 Data Driven Design
Lecture 6 Data Driven Design
Sur College of Applied Sciences
 
Lecture 9 Usability Orignal
Lecture 9 Usability Orignal
Sur College of Applied Sciences
 
Code This, Not That: 10 Do's and Don'ts For Learning HTML
Code This, Not That: 10 Do's and Don'ts For Learning HTML
HubSpot
 
Basic HTML
Basic HTML
coachhahn
 
Html journal chris kweks (microbold)
Html journal chris kweks (microbold)
Chris Kwekowe
 
Lecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITP
yucefmerhi
 
Lecture 3 Javascript1
Lecture 3 Javascript1
Sur College of Applied Sciences
 
Lesson plan: HTML Formatting Texts and Paragraphs
Lesson plan: HTML Formatting Texts and Paragraphs
Keith Borgonia Manatad
 
Introduction to basic HTML [Librarian edition]
Introduction to basic HTML [Librarian edition]
Kosie Eloff
 
Introduction to html fundamental concepts
Introduction to html fundamental concepts
Tsebo Shaun Masilo
 
Module 2 Lesson 1
Module 2 Lesson 1
claytors
 
Html 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally Chohan
ballychohanuk
 
Lecture 2 introduction to html basics
Lecture 2 introduction to html basics
AliMUSSA3
 
Getting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent Sourcing
Glenn Gutmacher
 
HTML validation, microformats, jQuery
HTML validation, microformats, jQuery
Jeffrey Barke
 
Lesson plan htmltextformattingtag
Lesson plan htmltextformattingtag
Keith Borgonia Manatad
 
Lesson plan 3
Lesson plan 3
Keith Borgonia Manatad
 
Html for beginners part I
Html for beginners part I
Unaib Aslam
 
Hypertext markup language (html)
Hypertext markup language (html)
Aksa Sahi
 
Basic html
Basic html
Drew Eric Noftle
 
javscript
javscript
rcc1964
 
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
Ivy Rueb
 
PL2235 2009 1 HTML
PL2235 2009 1 HTML
Aliamat UBD
 
Chapter 2 introduction to html5
Chapter 2 introduction to html5
nobel mujuji
 
Rails Girls - Introduction to HTML & CSS
Rails Girls - Introduction to HTML & CSS
Timo Herttua
 
Hidden Profit
Hidden Profit
Linctel Ltd
 
Friendship
Friendship
Sonja Ridden
 

More Related Content

What's hot (20)

Lecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITP
yucefmerhi
 
Lecture 3 Javascript1
Lecture 3 Javascript1
Sur College of Applied Sciences
 
Lesson plan: HTML Formatting Texts and Paragraphs
Lesson plan: HTML Formatting Texts and Paragraphs
Keith Borgonia Manatad
 
Introduction to basic HTML [Librarian edition]
Introduction to basic HTML [Librarian edition]
Kosie Eloff
 
Introduction to html fundamental concepts
Introduction to html fundamental concepts
Tsebo Shaun Masilo
 
Module 2 Lesson 1
Module 2 Lesson 1
claytors
 
Html 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally Chohan
ballychohanuk
 
Lecture 2 introduction to html basics
Lecture 2 introduction to html basics
AliMUSSA3
 
Getting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent Sourcing
Glenn Gutmacher
 
HTML validation, microformats, jQuery
HTML validation, microformats, jQuery
Jeffrey Barke
 
Lesson plan htmltextformattingtag
Lesson plan htmltextformattingtag
Keith Borgonia Manatad
 
Lesson plan 3
Lesson plan 3
Keith Borgonia Manatad
 
Html for beginners part I
Html for beginners part I
Unaib Aslam
 
Hypertext markup language (html)
Hypertext markup language (html)
Aksa Sahi
 
Basic html
Basic html
Drew Eric Noftle
 
javscript
javscript
rcc1964
 
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
Ivy Rueb
 
PL2235 2009 1 HTML
PL2235 2009 1 HTML
Aliamat UBD
 
Chapter 2 introduction to html5
Chapter 2 introduction to html5
nobel mujuji
 
Rails Girls - Introduction to HTML & CSS
Rails Girls - Introduction to HTML & CSS
Timo Herttua
 
Lecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITP
yucefmerhi
 
Lesson plan: HTML Formatting Texts and Paragraphs
Lesson plan: HTML Formatting Texts and Paragraphs
Keith Borgonia Manatad
 
Introduction to basic HTML [Librarian edition]
Introduction to basic HTML [Librarian edition]
Kosie Eloff
 
Introduction to html fundamental concepts
Introduction to html fundamental concepts
Tsebo Shaun Masilo
 
Module 2 Lesson 1
Module 2 Lesson 1
claytors
 
Html 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally Chohan
ballychohanuk
 
Lecture 2 introduction to html basics
Lecture 2 introduction to html basics
AliMUSSA3
 
Getting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent Sourcing
Glenn Gutmacher
 
HTML validation, microformats, jQuery
HTML validation, microformats, jQuery
Jeffrey Barke
 
Html for beginners part I
Html for beginners part I
Unaib Aslam
 
Hypertext markup language (html)
Hypertext markup language (html)
Aksa Sahi
 
javscript
javscript
rcc1964
 
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
Ivy Rueb
 
PL2235 2009 1 HTML
PL2235 2009 1 HTML
Aliamat UBD
 
Chapter 2 introduction to html5
Chapter 2 introduction to html5
nobel mujuji
 
Rails Girls - Introduction to HTML & CSS
Rails Girls - Introduction to HTML & CSS
Timo Herttua
 

Viewers also liked (7)

Hidden Profit
Hidden Profit
Linctel Ltd
 
Friendship
Friendship
Sonja Ridden
 
Life On A Train
Life On A Train
MJD Management Group
 
Friendship
Friendship
Sonja Ridden
 
Race
Race
sabinecharette
 
Presentation at Milagrow SME Conference
Presentation at Milagrow SME Conference
rajeshjain
 
Lecture 10 Image Format
Lecture 10 Image Format
Sur College of Applied Sciences
 
Ad

Similar to Lecture2 CSS 2 (20)

Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
umoren
 
Advanced Cascading Style Sheets
Advanced Cascading Style Sheets
fantasticdigitaltools
 
Css class-02
Css class-02
Md Ali Hossain
 
Css Introduction
Css Introduction
SathyaseelanK1
 
Web Design & Development - Session 2
Web Design & Development - Session 2
Shahrzad Peyman
 
CSS
CSS
BG Java EE Course
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
Hatem Mahmoud
 
Web Development 4 (HTML & CSS)
Web Development 4 (HTML & CSS)
ghayour abbas
 
Web Development 4
Web Development 4
ghayour abbas
 
1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf
AAFREEN SHAIKH
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
Css tutorial
Css tutorial
Mohamed Idris
 
Css tutorial
Css tutorial
Fakhrul Islam Talukder
 
Css tutorial by [email protected]
Css tutorial by [email protected]
vivek698
 
Css tutorial
Css tutorial
Edress Oryakhail
 
Csstutorial
Csstutorial
Ankit Rana
 
Html
Html
Jyotishankar Mohanty
 
CSS Foundations, pt 1
CSS Foundations, pt 1
Shawn Calvert
 
Css basics
Css basics
mirza asif haider
 
website design mark-up with HTML 5 .pptx
website design mark-up with HTML 5 .pptx
geremilibrary
 
Ad

More from Sur College of Applied Sciences (8)

Lecture11 A Image
Lecture11 A Image
Sur College of Applied Sciences
 
Lecture 11 B Security
Lecture 11 B Security
Sur College of Applied Sciences
 
Accessibility Usability Professional Summry
Accessibility Usability Professional Summry
Sur College of Applied Sciences
 
Lecture 8 Video
Lecture 8 Video
Sur College of Applied Sciences
 
Lecture 5 XML
Lecture 5 XML
Sur College of Applied Sciences
 
Lecture2 CSS 3
Lecture2 CSS 3
Sur College of Applied Sciences
 
Lecture2 CSS1
Lecture2 CSS1
Sur College of Applied Sciences
 
Navigation1 A
Navigation1 A
Sur College of Applied Sciences
 

Recently uploaded (20)

Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
RAKESH SAJJAN
 
Environmental Science, Environmental Health, and Sanitation – Unit 3 | B.Sc N...
Environmental Science, Environmental Health, and Sanitation – Unit 3 | B.Sc N...
RAKESH SAJJAN
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Health Care Planning and Organization of Health Care at Various Levels – Unit...
Health Care Planning and Organization of Health Care at Various Levels – Unit...
RAKESH SAJJAN
 
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
RAKESH SAJJAN
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDM & Mia eStudios
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
RAKESH SAJJAN
 
Environmental Science, Environmental Health, and Sanitation – Unit 3 | B.Sc N...
Environmental Science, Environmental Health, and Sanitation – Unit 3 | B.Sc N...
RAKESH SAJJAN
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Health Care Planning and Organization of Health Care at Various Levels – Unit...
Health Care Planning and Organization of Health Care at Various Levels – Unit...
RAKESH SAJJAN
 
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
RAKESH SAJJAN
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDM & Mia eStudios
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 

Lecture2 CSS 2

  • 1. Lecture 2: CSS II SFDV2001 Web Development
  • 2. The Box Model In CSS every element in your HTML file is contained within a rectangular box. There are four main components to this box: Content Margin Padding Border Additionally there a couple of background components: background colour background image
  • 3. Image source: http://www.hicksdesign.co.uk/boxmodel/
  • 4. The Box Model Margins are always transparent. Padding is the space between the content and the border. Background colour and/or image extend throughout the box model to the border. If a style of border used has gaps in it (e.g. dashed), the background shows through those gaps. The background of the parent element shows through the margin area of the box.
  • 5. Width The width set for an element is the width of the content . Padding, border and margin are additional to this width. h1{ width: 300px; padding: 5px; border: solid 10px #ff69b4; margin: 10px; } Total width on page for this element = 350 pixels Unless your IE: IE implements the box model incorrectly.
  • 6.  
  • 7. IE 5 (Mac) Safari Firefox
  • 9. Solutions There are hacks to combat many of the flaws in IE’s CSS rendering. Most exploit other IE bugs to provide workarounds. The Box Model hack (by Tantek Çelik) width: 350px; voice-family:”\”}\””; voice-family: inherit; width: 300px; IE doesn’t see the second width specification.
  • 10. Selectors Recap: selector{ property: value; } There are many different kinds of selectors: Standard element selectors Contextual selectors Class selectors ID selectors Pseudoselectors
  • 11. Element selectors H1{ color: #456678; } You can group selectors: H1, p, li{ color: #456678; } You can affect any element using the universal ( * ) selector.
  • 12. Contextual Selectors Allow you to affect elements based on their context. That is, their relationship to other elements. Descendant selectors Elements that are contained within other elements: ul li{ color: #456678; } ul li a{ color: #456678; }
  • 13. Contextual Selectors Child Selectors Similar to descendant selectors but it target only a direct child of an element: p > em{ color: #456678; }
  • 14. Contextual Selectors Adjacent sibling selectors H1 + p{ margin-left: 5%; } Affects an element that comes immediately after another. In the above example the first paragraph after a top-level heading will be indented.
  • 15. Class and ID selectors You can’t always style every element you want to with the standard selectors available and some times you need to make your own. There are two kinds of “custom-made” selectors: class and ID . Class is used for a style that you may wish to use multiple times in a single html file. ID is used for a style you wish to be unique in any one html file. You must set the class or ID in your HTML code.
  • 16. Class and ID selectors IDs take care of unique structural elements: Class is used for elements that are used multiple times : Heading Navigation Footer
  • 17.  
  • 18. Class and ID selectors In your style sheet: Class p.question{ color: navy; } Or .question{ color: navy; }
  • 19. Class and ID selectors In your style sheet: ID Div#footer{ border-top: solid 1px #555555; font-size: smaller; } Or #footer{ border-top: solid 1px #555555; font-size: smaller; }
  • 20. Class and ID selectors Resist the temptation to make everything a class. Make sure your id and class names are descriptive. “navigation” is descriptive of the function of the selector rather than the style. “red” is descriptive of a style - styles change. If you can use a contextual selector or the like instead of a class or ID, do so.
  • 21. Pseudoselectors Some things that you want to style in an html document are not possible to represent with standard element selectors because there is no element in your HTML document to represent them. Different link states - visited, unvisited etc. are good examples. Pseudoselectors enable you to identify these portions of elements. Pseudoselectors are identified in your CSS using a colon. a:link
  • 22. Pseudoselectors - Anchors Pseudoselectors are most commonly used to influence different link states. a:link a:visited a:hover a:active In transitional code the equivalents are the link , vlink and alink attributes of body. In CSS you get an extra link state (hover) and you can influence any aspect of a links style, not just colour.
  • 23. Pseudoselectors - Anchors a:link{ text-decoration: none; ... } a:visited{ color:#555555; ... } a:hover{ text-decoration: underline; } a:active{ color:#f6dc3b; ... }
  • 24. Pseudoselectors - Anchors Anchor pseudoselectors should appear in your CSS in the order: a a:link a:visited a:hover a:active If you don't, they may not function as they should. Putting : link last for example would override the : hover and : active states.
  • 25. Other pseudoselectors There are other pseudoselectors, but they aren't as commonly used as those associated with anchors because of poor browser support. :focus :first-child :first-line :first-letter :before :after :first-line and :first-letter are currently the only ones of this list that have any reasonable browser support.
  • 26. Block-level and Inline elements In html there are block elements and inline elements. The distinction between the two is important for how they may be nested. You know from transitional code that <font> tags only validate when used inside <p> tags. This is because <font> is an inline element and <p> is a block level element. Block-level elements can contain other block-level elements and inline elements. Inline elements can only contain content and other inline elements.
  • 27.  
  • 28. Block-Level and Inline in CSS CSS allows you to explicitly state if an element is block-level or inline. BUT! These have nothing to do with the structure of your HTML and will not change the rules of validation. The notions of block-level and inline in CSS are presentation concepts only. display: block; display: inline;
  • 29.  
  • 30.  
  • 31. Recommended sites: Hicks Design Box Model diagram: http://www.hicksdesign.co.uk/3dboxmodel/ Interactive Box Model diagram: http://www.redmelon.net/tstme/box_model/ W3C's Box Model description: http://www.w3.org/TR/REC-CSS2/box.html Tantek Çelik's Box Model hack: http://tantek.com/CSS/Examples/boxmodelhack.html Further reading: Web Design in a Nutshell, 3rd Edition by Jennifer Niederst Robbins

Editor's Notes

  • #5: Show boxModel.html
  • #7: Top = doctype - “standards mode” As pages will appear in IE 6 and up with a doctype Bottom = no doctype - “quirks mode” As pages appear in IE 5 and prior and for files without the right doctype. In version 6, Microsoft addressed this issue by implementing the W3C box model, if &amp;quot;standards mode&amp;quot; was enabled, which is done by defining a supported DOCTYPE on the first line of the HTML output.
  • #10: The &amp;quot;box model hack&amp;quot; developed by Tantek Çelik . Developed during his time at Microsoft working on Internet Explorer for the Macintosh, which is not affected by the bug — involves specifying a width for Internet Explorer for Windows which is then over-ridden by another width specification. This second specification is hidden from Internet Explorer for Windows by exploiting a bug in the way that browser parses CSS rules. width: 350px; - Width for IE voice-family:””}””; - IE is tricked into thinking rule has finished voice-family: inherit; - voice-family is reset for any browser that understands the property width: 300px; - the &amp;quot;real&amp;quot; width is set for all other browsers.
  • #11: Also attribute selectors but these are so poorly supported at present that I’m not going to talk about them here.
  • #14: First em is affected. Second is not.
  • #23: Don&apos;t forget plain a
  • #25: a
  • #26: Focus - can be applied to any element but in the few browsers that offer any support for it, generally only form elements can make use of it. Firstchild - as it suggests - e.g. Li:first-child - targets the first li of a list. Before and after allow for generated content to be inserted before or after an element: Blockquote:before{content:&amp;quot;&amp;#8220;&amp;quot; font-size: 24px} Blockquote:after{content:&amp;quot;&amp;#8220;&amp;quot; font-size: 24px} There is also :lang(ab).