SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Castro Chapter 7

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
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.
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
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
 
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
 

Kürzlich hochgeladen (20)

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
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...
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
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
 
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
 

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 */