SlideShare a Scribd company logo
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

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
Lee Cheneler
 
Basic css
Basic cssBasic css
Basic css
Gopinath Ambothi
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
Sun Technlogies
 
Html Expression Web
Html Expression WebHtml Expression Web
Html Expression Web
Mark Frydenberg
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
tutorialsruby
 
Intro to CSS
Intro to CSSIntro to CSS
Intro to CSS
Randy Oest II
 
Css
CssCss
Cascading style sheets - CSS
Cascading style sheets - CSSCascading style sheets - CSS
Cascading style sheets - CSS
iFour Institute - Sustainable Learning
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing world
Russ Weakley
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSS
Hawkman Academy
 
CSS
CSSCSS
Css intro
Css introCss intro
Css intro
Julia Vi
 
Css basics
Css basicsCss basics
Css basics
ASIT
 
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
Marc Huang
 
Intro to HTML + CSS
Intro to HTML + CSSIntro to HTML + CSS
Intro to HTML + CSS
Jamal Sinclair O'Garro
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
Rob Friesel
 
Css 3
Css 3Css 3
Css 3
poollar
 
Css 3
Css 3Css 3
Css 3
poollar
 
CSS
CSSCSS
CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
Russ Weakley
 

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 6
Jeff Byrnes
 
Castro Chapter 15
Castro Chapter 15Castro Chapter 15
Castro Chapter 15
Jeff Byrnes
 
Castro Chapter 4
Castro Chapter 4Castro Chapter 4
Castro Chapter 4
Jeff Byrnes
 
Castro Chapter 3
Castro Chapter 3Castro Chapter 3
Castro Chapter 3
Jeff Byrnes
 
Financial analysis pp
Financial analysis ppFinancial analysis pp
Financial analysis pp
JoeVelarde
 
Castro Chapter 5
Castro Chapter 5Castro Chapter 5
Castro Chapter 5
Jeff Byrnes
 
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2
Jeff Byrnes
 
INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1
Jeff 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

Unit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology projectUnit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology project
abhiramhatwar
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
karthiksmart21
 
CSS.pptx
CSS.pptxCSS.pptx
Chapter 11: Intro to CSS
Chapter 11: Intro to CSSChapter 11: Intro to CSS
Chapter 11: Intro to CSS
Steve Guinan
 
Unit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxUnit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptx
Tanu524249
 
Intro to html, css & sass
Intro to html, css & sassIntro to html, css & sass
Intro to html, css & sass
Sean Wolfe
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
eShikshak
 
DHTML
DHTMLDHTML
Css
CssCss
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
Thapar Institute
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
Stefan Oprea
 
Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
Peter Kaizer
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
Abhishek Kesharwani
 
Css
CssCss
Css
CssCss
Week11 Lecture: CSS
Week11 Lecture: CSSWeek11 Lecture: CSS
Web Development - Lecture 5
Web Development - Lecture 5Web Development - Lecture 5
Web Development - Lecture 5
Syed Shahzaib Sohail
 
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
alvindalejoyosa1
 
CSS Topic wise Short notes ppt by Navya.E
CSS Topic wise Short notes ppt by Navya.ECSS Topic wise Short notes ppt by Navya.E
CSS Topic wise Short notes ppt by Navya.E
NavyaEnugala
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
MattMarino13
 

Similar to Castro Chapter 7 (20)

Unit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology projectUnit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology project
 
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
 
CSS Topic wise Short notes ppt by Navya.E
CSS Topic wise Short notes ppt by Navya.ECSS Topic wise Short notes ppt by Navya.E
CSS Topic wise Short notes ppt by Navya.E
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
 

More from Jeff Byrnes

Castro Chapter 11
Castro Chapter 11Castro Chapter 11
Castro Chapter 11
Jeff Byrnes
 
Castro Chapter 10
Castro Chapter 10Castro Chapter 10
Castro Chapter 10
Jeff Byrnes
 
Castro Chapter 9
Castro Chapter 9Castro Chapter 9
Castro Chapter 9
Jeff Byrnes
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8
Jeff Byrnes
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
Jeff Byrnes
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
Jeff 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

RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 

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