SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a Castro Chapter 7

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Último (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

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