SlideShare a Scribd company logo
1 of 21
STYLE SHEET
BUILDING BLOCKS
HTML5 & CSS Visual Quickstart Guide
Chapter 7
Our Special Guest: the Cascading Style
Sheet
• HTML gives Web pages their basic structure
• Cascading Style Sheets (CSS) defines their appearance
• What is a style sheet?
• A text file containing one or more rules that determine how certain
elements in your Web page should be
displayed.
• Done via properties and values
• Currently, best supported version of CSS is CSS 2.
• CSS 3 is catching up!
• Modern browsers already support several CSS3 components
What Can I Do With CSS?
• CSS properties can control:
• Font size & color
• Layout properties (like positioning and float)
• Print controls for deciding where page breaks should appear
• Dynamic properties, which allow items to appear & disappear
• Useful for creating drop-down menus and other interactive components.
Constructing a Style Rule
• Each style rule has two main parts: the selector and the
declaration.
• Selector determines which elements are affected by the rule
• Declaration specifies just what should be done through one or
more property/value pairs.
• To construct a style rule:
• selector { property: value; }
• h1 { color: red; }
• h1 { color: red;
background: yellow; }
• Can add extra spaces, tabs, or returns to keep style sheet
readable
• Missing (or duplicate) semicolons can (and often do!)
break the style rule!
Adding Comments to Style Rules
• Commenting your style rules is even more important than
commenting your HTML.
• Done differently than in HTML—CSS commenting is more
like C or C++ commenting
• /* This is a comment in CSS */
• May include returns, so your comment can span several
lines
• Comments are a great way to temporarily disable style
rules!
• No nested comments!
When Rules Collide: the Cascade
• Quite often, it will be possible for more than one style rule
that applies to a given element
• Every browser has a default style sheet
• You can write style rules and apply them to a specific HTML
element right in the code
• You might have style rules at the type of your document
• You might import style rules from another file
• Some browsers allow your visitors to create and apply their own
style sheets to any pages they visit
• Some styles are inherited from parent element to child.
• This creates a collision
How to Decide Which Rule to Follow?
• CSS uses principle of the cascade to determine this
• Takes into account inheritance, specificity, and location in order to
determine which of a group of conflicting rules should win out
• Follows those principles in that order!
• Specificity is more important in CSS than inheritance.
• Location is more important than specificity.
Inheritance
• Many CSS properties are inherited by the descendants of
those elements
• Remember our discussion of parents and children back at the
beginning of the semester? Yeah…we’re back to that.
• Not all CSS properties can be inherited (border cannot be
inherited.)
• Individual section of text covering each property (and Appendix B)
details whether or not a property can be inherited.
• For example, you could set a rule that says every <p>
element will be blue. Inside one of your <p> elements,
you have a <em> element. What color will the <em>
element be, if you don’t have a rule for <em>?
Specificity
• When more than one rule is applied to an element, the
law of specificity states that the more specific the selector,
the stronger the rule.
• If one rule states that all h1 elements should be blue, but
a second rule states that all h1 elements with a class of
Spanish should be red, the second rule overrides the first
for all those h1 elements whose class is Spanish.
• Important note: id attributes are considered the most
specific, since they’re unique in a document!
• For the exact rules of calculating specificity, see Section
6.4.3 of the CSS specifications
• http://www.w3.org/TR/CSS21/cascade.html#specificity
Location
• If specificity isn’t enough to determine a winner among
competing rules, location trumps ‘em all
• The location of the rule breaks the tie
• Rules that appear later have more weight
• Rules applied locally (right inside the HTML element) are
considered to appear after rules at the top of the HTML document
• The basic rule is this: all else being equal, the later the style
appears, the more precedence or importance it has
Visualizing Location
Imported Style
Sheet Rules
Style Rules Imported by
Other Imported Style Sheets
Style Rules in
<head> of
Web Page
Style Rules in
the Element
Itself
Rules with
!important
at the end.
A Property’s Value
• Each CSS property has different rules about what values
it can accept:
• Some properties only accept one of a list of predefined values.
• Others accept numbers, integers, relative values, percentages,
URLs, or colors.
• Some can accept more than one value.
• Inherit value: use for any property value when you
want to explicitly specify that the value for that property
should be the same as that of the element’s parent.
• Predefined Values exist for most CSS properties:
• The display property can be set to block, inline, list-item, or
none
• Difference between HTML and CSS: predefined values cannot be
enclosed in quotation marks!
A Property’s Value (cont’d)
• Many CSS properties take a length for their value
• All length values must contain a quantity and a unit, with
no spaces between them
• 3em
• 10px
• Some length types are relative to other values
• An em is usually equal to the element’s font-size
• 2em would mean “twice the font size.”
• Pixels (px) are relative to the resolution of the monitor
• Most monitors display 80ppi (but range from 72ppi to 96ppi)
• 16 pixels is about 1/5 of an inch (0.5cm)
A Property’s Value (cont’d again)
• There are also absolute units
• inches (in)
• centimeters (cm)
• millimeters (mm)
• points (pt)
• picas (pc)
• Only use absolute units when the size of the output is known, as
with the printed page.
• Percentage values, like 65%, work like ems—they’re
relative to some other value
A Property’s Value (cont’d for the last
time!)
• A few CSS properties accept a bare number as a value.
• line-height
• line-height: 1.5;
• z-index
• There are others, but they’re mostly used for print and aural style
sheets and are not yet well supported
• Some CSS properties allow you to specify the URL of
another file
• Use url(file.ext) where file.ext is the path and file name of
the desired document.
• background: url(bg_flax.jpg);
• You can use quotation marks around the file name, but they’re not
required.
• But! There cannot be any space between the word url and the opening
parentheses!
CSS Colors
• Several ways to specify colors for CSS properties
• One of 16 predefined color names
• color: yellow;
• Specifying the red/green/blue amounts
• color: rgb(35%, 0%, 50%);
• Your text puts the % before 35; this might work in some browsers, but it’s not
universally supported!
• color: rgb(89, 0, 127);
• Specifying the hexadecimal value
• color: #59007F;
CSS3 Color Options — RGBA
• RGBA is the same as RGB, except…
• The A stands for alpha transparency
• Decimal from 0 to 1 after red, green, blue values
• property: rgba(red, green, blue, alpha transparency);
• Closer to 0 the alpha setting, the more transparent
• 0 is completely transparent
• 1 is completely opaque
RGBA Examples
• /* no transparency, so the same as rgb(89, 0, 127); */
background: rgba(89,0,127,1);
• /* completely transparent */
background: rgba(89,0,127,0);
• /* 25% transparent */
background: rgba(89,0,127,0.75);
• /* 60% transparent */
• background: rgba(89,0,127,0.4);
CSS3 Color Options – HSL & HSLA
• Hue, Saturation, Lightness
• Hue: number from 0-360
• Saturation & Lightness: percentages from 0-100
• color: hsl(282, 100%, 25%);
• HSLA adds alpha transparency
• /* 25% transparent */
h1 {
background: hsla(282,100%, 25%,0.75);
}
A Warning on CSS3 Color Options
• No version of Internet Explorer prior to IE9 supports rgba,
hsl, or hsla
• Ignores any declaration it doesn’t understand
• Best workaround is to provide a fallback color declaration
• background: #59007f; /* for pre-IE9 */
background: rgba(89,0,127,0.75); /* All other browsers */
Sixteen Predefined Colors
Aqua
#00FFFF
Black
#000000
Blue
#0000FF
Fuchsia
#FF00FF
Gray
#808080
Green
#008000
Lime
#00FF00
Maroon
#800000
Navy
#000080
Olive
#808000
Purple
#800080
Red
#FF0000
Silver
#C0C0C0
Teal
#008080
White
#FFFFFF
Yellow
#FFFF00

More Related Content

What's hot (20)

Sane CSS - A modern approach to CSS
Sane CSS - A modern approach to CSSSane CSS - A modern approach to CSS
Sane CSS - A modern approach to CSS
 
Basic css
Basic cssBasic css
Basic css
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Html Expression Web
Html Expression WebHtml Expression Web
Html Expression Web
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
Intro to CSS
Intro to CSSIntro to CSS
Intro to CSS
 
Css
CssCss
Css
 
Cascading style sheets - CSS
Cascading style sheets - CSSCascading style sheets - CSS
Cascading style sheets - CSS
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing world
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSS
 
CSS
CSSCSS
CSS
 
Css intro
Css introCss intro
Css intro
 
Css basics
Css basicsCss basics
Css basics
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascript
 
Intro to HTML + CSS
Intro to HTML + CSSIntro to HTML + CSS
Intro to HTML + CSS
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
 
Css 3
Css 3Css 3
Css 3
 
Css 3
Css 3Css 3
Css 3
 
CSS
CSSCSS
CSS
 
CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
 

Viewers also liked

Castro Chapter 6
Castro Chapter 6Castro Chapter 6
Castro Chapter 6Jeff Byrnes
 
Castro Chapter 15
Castro Chapter 15Castro Chapter 15
Castro Chapter 15Jeff Byrnes
 
Castro Chapter 4
Castro Chapter 4Castro Chapter 4
Castro Chapter 4Jeff Byrnes
 
Castro Chapter 3
Castro Chapter 3Castro Chapter 3
Castro Chapter 3Jeff Byrnes
 
Financial analysis pp
Financial analysis ppFinancial analysis pp
Financial analysis ppJoeVelarde
 
Castro Chapter 5
Castro Chapter 5Castro Chapter 5
Castro Chapter 5Jeff Byrnes
 
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2Jeff Byrnes
 
INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1Jeff Byrnes
 

Viewers also liked (8)

Castro Chapter 6
Castro Chapter 6Castro Chapter 6
Castro Chapter 6
 
Castro Chapter 15
Castro Chapter 15Castro Chapter 15
Castro Chapter 15
 
Castro Chapter 4
Castro Chapter 4Castro Chapter 4
Castro Chapter 4
 
Castro Chapter 3
Castro Chapter 3Castro Chapter 3
Castro Chapter 3
 
Financial analysis pp
Financial analysis ppFinancial analysis pp
Financial analysis pp
 
Castro Chapter 5
Castro Chapter 5Castro Chapter 5
Castro Chapter 5
 
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2
 
INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1
 

Similar to Castro Chapter 7

Similar to Castro Chapter 7 (20)

WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
Chapter 11: Intro to CSS
Chapter 11: Intro to CSSChapter 11: Intro to CSS
Chapter 11: Intro to CSS
 
Unit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxUnit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptx
 
Intro to html, css & sass
Intro to html, css & sassIntro to html, css & sass
Intro to html, css & sass
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
DHTML
DHTMLDHTML
DHTML
 
Css
CssCss
Css
 
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
 
Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
 
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
CssCss
Css
 
Week11 Lecture: CSS
Week11 Lecture: CSSWeek11 Lecture: CSS
Week11 Lecture: CSS
 
Web Development - Lecture 5
Web Development - Lecture 5Web Development - Lecture 5
Web Development - Lecture 5
 
Cascading Style Sheets for web browser.pptx
Cascading Style Sheets for web browser.pptxCascading Style Sheets for web browser.pptx
Cascading Style Sheets for web browser.pptx
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
 
basic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfbasic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdf
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 

More from Jeff Byrnes

Castro Chapter 11
Castro Chapter 11Castro Chapter 11
Castro Chapter 11Jeff Byrnes
 
Castro Chapter 10
Castro Chapter 10Castro Chapter 10
Castro Chapter 10Jeff Byrnes
 
Castro Chapter 9
Castro Chapter 9Castro Chapter 9
Castro Chapter 9Jeff Byrnes
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8Jeff Byrnes
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2Jeff Byrnes
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2Jeff Byrnes
 

More from Jeff Byrnes (6)

Castro Chapter 11
Castro Chapter 11Castro Chapter 11
Castro Chapter 11
 
Castro Chapter 10
Castro Chapter 10Castro Chapter 10
Castro Chapter 10
 
Castro Chapter 9
Castro Chapter 9Castro Chapter 9
Castro Chapter 9
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
 

Recently uploaded

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 

Castro Chapter 7

  • 1. STYLE SHEET BUILDING BLOCKS HTML5 & CSS Visual Quickstart Guide Chapter 7
  • 2. Our Special Guest: the Cascading Style Sheet • HTML gives Web pages their basic structure • Cascading Style Sheets (CSS) defines their appearance • What is a style sheet? • A text file containing one or more rules that determine how certain elements in your Web page should be displayed. • Done via properties and values • Currently, best supported version of CSS is CSS 2. • CSS 3 is catching up! • Modern browsers already support several CSS3 components
  • 3. What Can I Do With CSS? • CSS properties can control: • Font size & color • Layout properties (like positioning and float) • Print controls for deciding where page breaks should appear • Dynamic properties, which allow items to appear & disappear • Useful for creating drop-down menus and other interactive components.
  • 4. Constructing a Style Rule • Each style rule has two main parts: the selector and the declaration. • Selector determines which elements are affected by the rule • Declaration specifies just what should be done through one or more property/value pairs. • To construct a style rule: • selector { property: value; } • h1 { color: red; } • h1 { color: red; background: yellow; } • Can add extra spaces, tabs, or returns to keep style sheet readable • Missing (or duplicate) semicolons can (and often do!) break the style rule!
  • 5. Adding Comments to Style Rules • Commenting your style rules is even more important than commenting your HTML. • Done differently than in HTML—CSS commenting is more like C or C++ commenting • /* This is a comment in CSS */ • May include returns, so your comment can span several lines • Comments are a great way to temporarily disable style rules! • No nested comments!
  • 6. When Rules Collide: the Cascade • Quite often, it will be possible for more than one style rule that applies to a given element • Every browser has a default style sheet • You can write style rules and apply them to a specific HTML element right in the code • You might have style rules at the type of your document • You might import style rules from another file • Some browsers allow your visitors to create and apply their own style sheets to any pages they visit • Some styles are inherited from parent element to child. • This creates a collision
  • 7. How to Decide Which Rule to Follow? • CSS uses principle of the cascade to determine this • Takes into account inheritance, specificity, and location in order to determine which of a group of conflicting rules should win out • Follows those principles in that order! • Specificity is more important in CSS than inheritance. • Location is more important than specificity.
  • 8. Inheritance • Many CSS properties are inherited by the descendants of those elements • Remember our discussion of parents and children back at the beginning of the semester? Yeah…we’re back to that. • Not all CSS properties can be inherited (border cannot be inherited.) • Individual section of text covering each property (and Appendix B) details whether or not a property can be inherited. • For example, you could set a rule that says every <p> element will be blue. Inside one of your <p> elements, you have a <em> element. What color will the <em> element be, if you don’t have a rule for <em>?
  • 9. Specificity • When more than one rule is applied to an element, the law of specificity states that the more specific the selector, the stronger the rule. • If one rule states that all h1 elements should be blue, but a second rule states that all h1 elements with a class of Spanish should be red, the second rule overrides the first for all those h1 elements whose class is Spanish. • Important note: id attributes are considered the most specific, since they’re unique in a document! • For the exact rules of calculating specificity, see Section 6.4.3 of the CSS specifications • http://www.w3.org/TR/CSS21/cascade.html#specificity
  • 10. Location • If specificity isn’t enough to determine a winner among competing rules, location trumps ‘em all • The location of the rule breaks the tie • Rules that appear later have more weight • Rules applied locally (right inside the HTML element) are considered to appear after rules at the top of the HTML document • The basic rule is this: all else being equal, the later the style appears, the more precedence or importance it has
  • 11. Visualizing Location Imported Style Sheet Rules Style Rules Imported by Other Imported Style Sheets Style Rules in <head> of Web Page Style Rules in the Element Itself Rules with !important at the end.
  • 12. A Property’s Value • Each CSS property has different rules about what values it can accept: • Some properties only accept one of a list of predefined values. • Others accept numbers, integers, relative values, percentages, URLs, or colors. • Some can accept more than one value. • Inherit value: use for any property value when you want to explicitly specify that the value for that property should be the same as that of the element’s parent. • Predefined Values exist for most CSS properties: • The display property can be set to block, inline, list-item, or none • Difference between HTML and CSS: predefined values cannot be enclosed in quotation marks!
  • 13. A Property’s Value (cont’d) • Many CSS properties take a length for their value • All length values must contain a quantity and a unit, with no spaces between them • 3em • 10px • Some length types are relative to other values • An em is usually equal to the element’s font-size • 2em would mean “twice the font size.” • Pixels (px) are relative to the resolution of the monitor • Most monitors display 80ppi (but range from 72ppi to 96ppi) • 16 pixels is about 1/5 of an inch (0.5cm)
  • 14. A Property’s Value (cont’d again) • There are also absolute units • inches (in) • centimeters (cm) • millimeters (mm) • points (pt) • picas (pc) • Only use absolute units when the size of the output is known, as with the printed page. • Percentage values, like 65%, work like ems—they’re relative to some other value
  • 15. A Property’s Value (cont’d for the last time!) • A few CSS properties accept a bare number as a value. • line-height • line-height: 1.5; • z-index • There are others, but they’re mostly used for print and aural style sheets and are not yet well supported • Some CSS properties allow you to specify the URL of another file • Use url(file.ext) where file.ext is the path and file name of the desired document. • background: url(bg_flax.jpg); • You can use quotation marks around the file name, but they’re not required. • But! There cannot be any space between the word url and the opening parentheses!
  • 16. CSS Colors • Several ways to specify colors for CSS properties • One of 16 predefined color names • color: yellow; • Specifying the red/green/blue amounts • color: rgb(35%, 0%, 50%); • Your text puts the % before 35; this might work in some browsers, but it’s not universally supported! • color: rgb(89, 0, 127); • Specifying the hexadecimal value • color: #59007F;
  • 17. CSS3 Color Options — RGBA • RGBA is the same as RGB, except… • The A stands for alpha transparency • Decimal from 0 to 1 after red, green, blue values • property: rgba(red, green, blue, alpha transparency); • Closer to 0 the alpha setting, the more transparent • 0 is completely transparent • 1 is completely opaque
  • 18. RGBA Examples • /* no transparency, so the same as rgb(89, 0, 127); */ background: rgba(89,0,127,1); • /* completely transparent */ background: rgba(89,0,127,0); • /* 25% transparent */ background: rgba(89,0,127,0.75); • /* 60% transparent */ • background: rgba(89,0,127,0.4);
  • 19. CSS3 Color Options – HSL & HSLA • Hue, Saturation, Lightness • Hue: number from 0-360 • Saturation & Lightness: percentages from 0-100 • color: hsl(282, 100%, 25%); • HSLA adds alpha transparency • /* 25% transparent */ h1 { background: hsla(282,100%, 25%,0.75); }
  • 20. A Warning on CSS3 Color Options • No version of Internet Explorer prior to IE9 supports rgba, hsl, or hsla • Ignores any declaration it doesn’t understand • Best workaround is to provide a fallback color declaration • background: #59007f; /* for pre-IE9 */ background: rgba(89,0,127,0.75); /* All other browsers */