SlideShare a Scribd company logo
Cascading Style Sheets Tushar Joshi
Basic Concepts Redefines a HTML tag. User Agent (often the browser) renders the HTML tag with this modified definition. There are around 50 properties used in CSS H1 { color: blue } Selector Declaration property value Simple CSS Rule
Basic Concepts Containment in HTML 1. Using LINK element in the HEAD tag to link to external style sheet. <HTML>  <HEAD>    <TITLE>title</TITLE>    <LINK REL=STYLESHEET TYPE=&quot;text/css“   HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;>   <STYLE TYPE=&quot;text/css&quot;>    @import url(http://style.com/basic);    H1 { color: blue }    </STYLE>  </HEAD>  <BODY>    <H1>Headline is blue</H1>    <P STYLE=&quot;color: green&quot;>   While the paragraph is green.  </BODY>  </HTML>
Basic Concepts Containment in HTML 2. Using STYLE element to write style definitions in the HTML file itself. <HTML>  <HEAD>    <TITLE>title</TITLE>    <LINK REL=STYLESHEET TYPE=&quot;text/css“   HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;>   <STYLE TYPE=&quot;text/css&quot;>    @import url(http://style.com/basic);    H1 { color: blue }    </STYLE>  </HEAD>  <BODY>    <H1>Headline is blue</H1>    <P STYLE=&quot;color: green&quot;>   While the paragraph is green.  </BODY>  </HTML>
Basic Concepts Containment in HTML 3. Importing another style sheet using @import notation. <HTML>  <HEAD>    <TITLE>title</TITLE>    <LINK REL=STYLESHEET TYPE=&quot;text/css“   HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;>   <STYLE TYPE=&quot;text/css&quot;>    @import url(http://style.com/basic);    H1 { color: blue }    </STYLE>  </HEAD>  <BODY>    <H1>Headline is blue</H1>    <P STYLE=&quot;color: green&quot;>   While the paragraph is green.  </BODY>  </HTML>
Basic Concepts Containment in HTML 4. Using style attribute in the HTML element. <HTML>  <HEAD>    <TITLE>title</TITLE>    <LINK REL=STYLESHEET TYPE=&quot;text/css“   HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;>   <STYLE TYPE=&quot;text/css&quot;>    @import url(http://style.com/basic);    H1 { color: blue }    </STYLE>  </HEAD>  <BODY>    <H1>Headline is blue</H1>    <P STYLE=&quot;color: green&quot;>   While the paragraph is green.  </BODY>  </HTML>
Basic Concepts Grouping Selectors can be grouped in comma separated lists Reduce the size of style sheet H1, H2, H3 { font-family: helvetica }
Basic Concepts Grouping Declarations can be grouped H1 {  font-weight: bold;  font-size: 12pt; line-height: 14pt;  font-family: helvetica;  font-variant: normal; font-style: normal; }
Basic Concepts Grouping Some properties have their own grouping syntax H1 { font: bold 12pt/14pt helvetica }
Basic Concepts Inheritance <H1>The headline <EM>is</EM> important!</H1> If EM tag has not been defined it takes (inherits) all the styles of enclosing H1 tag. If color of H1 is blue and EM has no defination for color it will be blue.
Basic Concepts Inheritance BODY {  color: black; background: url(texture.gif) white; } Sets default style for whole document as BODY is the enclosing tag for all. Text color will be black and background will be texture.gif graphics. If graphic file is missing background will be white.
Basic Concepts Class as selector Defines “pastoral” as a named style for tag H1 Any elements inside BODY tag can be classed.  <HTML> <HEAD> <TITLE>Title</TITLE> <STYLE TYPE=&quot;text/css&quot;> H1.pastoral { color: #00FF00 } </STYLE> </HEAD> <BODY> <H1 CLASS=pastoral>Way too green</H1> </BODY> </HTML>
Basic Concepts Class as selector All elements can be addressed by omitting the tag name selector.  All elements with class pastoral will be shown in the color defined in the style. <HTML> <HEAD> <TITLE>Title</TITLE> <STYLE TYPE=&quot;text/css&quot;> .pastoral { color: #00FF00 } </STYLE> </HEAD> <BODY> <H1 CLASS=pastoral>Way too green</H1>   <P CLASS=pastoral>My Paragraph</P> </BODY> </HTML>
Basic Concepts ID as selectors #z97y  {letter-spacing: 9am } Name starting with # denoted ID selector. Any element having ID z97y will be applied with this style.
Basic Concepts ID as selectors H1#z97y  {letter-spacing: 9am } Only H1 tag with ID z97y will be selected for application of this style.
Basic Concepts Contextual Selectors H1 EM { color: red } Only EM elements inside H1 tags will be selected to apply color red. H1 EM becomes the pattern to be searched.
Basic Concepts Contextual Selectors More Examples DIV P  { font: small sans-serif } P element only inside any DIV tag .reddish H1 { color: red } H1 element only inside any tag having class attribute reddish #x78y CODE { background: blue } CODE element only inside the tag having ID x78y DIV.sidenote H1 { font-size: large } H1 element only inside DIV element having class as sidenote
Basic Concepts Contextual Selectors Can be grouped together. H1 B, H2 B, H1 EM, H2 EM { color: red } Equivalent to: H1 B { color: red } H2 B { color: red } H1 EM { color: red } H2 EM { color: red }
Basic Concepts Comments in style sheets EM { color: red }  /* red, really red!! */ Textual comments in CSS style sheets are just like comments for C language. Comments are ignored by CSS parser.
Basic Concepts Anchor pseudo-classes Different visual states of anchor tags are represented by pseudo-classes A:link { color: red }  /* unvisited link */ A:visited { color: blue }  /* visited links */ A:active { color: lime }  /* active links */
Basic Concepts Anchor pseudo-classes Pseudo classes can be used in conjunction with normal classes. A.alpha:link { color: red }  /* unvisited link */ A.beta:visited { color: blue }  /* visited links */ A.gamma:active { color: lime }  /* active links */ <a class=alpha>Click Me</a>
Basic Concepts Anchor pseudo-classes Pseudo classes can be used in contextual selectors All IMG tags only inside A tag will have solid red border. A:link IMG { border: solid red } <A class=alpha><IMG SRC=flower.gif></A>
Basic Concepts The Cascade A style sheet designer can combine several (partial) style sheets to reduce redundancy: @import url(http://www.style.org/pastoral); @import url(http://www.style.org/marine); H1 { color: red }  /* override imported sheets */ In CSS1,  all '@import' statements must occur  at the start of a style sheet
Basic Concepts The Cascade Author Reader Balance Both readers and authors can influence the presentation through style sheets.  Authors explicitly apply style sheets, readers can selectively use them or not. Conflict resolution is based on each style rule having a weight.  By default, the weights of the reader's rules are less than the weights of rules in the author's documents.
Basic Concepts ‘important’ keyword Weights of the declarations can be increased: H1 { color: black ! important; background: white ! important } P  { font-size: 12pt ! important; font-style: italic } In the example above, the first three declarations have increased weight, while the last declaration has normal weight.
Basic Concepts Box-oriented formatting model  Each formatted element results in one or more rectangular boxes.  Elements that have a 'display' value of 'none' are not formatted and will therefore not result in a box. All boxes have a core content area with optional surrounding padding, border and margin areas. Formatting Model
Basic Concepts Block Level Elements <STYLE TYPE=&quot;text/css&quot;>  UL {  background: red;  margin: A B C D;  padding: E F G H;  }  LI {  color: white;  background: blue;  /* so text is white on blue */  margin: a b c d;  padding: e f g h;  }  </STYLE> ..  <UL>  <LI>1st element of list  <LI>2nd element of list </UL>
Reference Material http://www.w3.org/TR/REC-CSS1 Save the material available for offline reference Use this material as reference, lexicon for properties and their default values CSS has much more to learn and this session should be taken as a starting point.

More Related Content

PPTX
New Elements & Features in HTML5
PPTX
Html form tag
PPTX
Html tags
PPTX
Basic HTML
PPTX
Html5 and-css3-overview
PPTX
HTML Frameset & Inline Frame
New Elements & Features in HTML5
Html form tag
Html tags
Basic HTML
Html5 and-css3-overview
HTML Frameset & Inline Frame

What's hot (20)

PPTX
PPTX
Model Your Application Domain, Not Your JSON Structures
PPTX
Css Basics
ODP
Cascading Style Sheets - Part 01
PDF
Javascript Basic
PPT
PHP POWERPOINT SLIDES
PPTX
Html ppt
PDF
javascript objects
PDF
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
PDF
Django Templates
PPT
Bootstrap Components Quick Overview
PDF
Html,javascript & css
PPT
CSS
PPT
CSS for Beginners
PPTX
PDF
JavaScript guide 2020 Learn JavaScript
PPTX
JavaScript Lecture notes.pptx
PPTX
jQuery
PPT
Introduction to CSS
PPTX
Bootstrap 5 whats new
Model Your Application Domain, Not Your JSON Structures
Css Basics
Cascading Style Sheets - Part 01
Javascript Basic
PHP POWERPOINT SLIDES
Html ppt
javascript objects
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
Django Templates
Bootstrap Components Quick Overview
Html,javascript & css
CSS
CSS for Beginners
JavaScript guide 2020 Learn JavaScript
JavaScript Lecture notes.pptx
jQuery
Introduction to CSS
Bootstrap 5 whats new
Ad

Viewers also liked (20)

PPT
PPT
Css advanced – session 4
PPTX
Introduction to CSS
PDF
Html Css
PPTX
Cashcading stylesheets
PPS
Cascading Style Sheets
ODP
An Introduction to Cascading Style Sheets (CSS3)
PPT
Cascading Style Sheets
PPT
Cascading Style Sheets By Mukesh
PPT
Cascading style sheets (css)
PPTX
Cascading style sheets - CSS
PPT
Cascading Style Sheets(CSS)
PDF
CSS Selectors
PPSX
CSS-Cascading Style Sheets - Introduction
PPT
CSS, CSS Selectors, CSS Box Model
PPTX
Cascading Style Sheets - CSS
PPT
Casestudy landscape ip park.
PDF
What is landscape? What is landscape architecture? What is landscape design? ...
Css advanced – session 4
Introduction to CSS
Html Css
Cashcading stylesheets
Cascading Style Sheets
An Introduction to Cascading Style Sheets (CSS3)
Cascading Style Sheets
Cascading Style Sheets By Mukesh
Cascading style sheets (css)
Cascading style sheets - CSS
Cascading Style Sheets(CSS)
CSS Selectors
CSS-Cascading Style Sheets - Introduction
CSS, CSS Selectors, CSS Box Model
Cascading Style Sheets - CSS
Casestudy landscape ip park.
What is landscape? What is landscape architecture? What is landscape design? ...
Ad

Similar to Introduction to Cascading Style Sheets (20)

PPTX
Design Dream
PPS
PPT
AK css
PPT
Understanding THML
ODP
Html intro
ODP
Html intro
PPT
Css Basics
PPT
Diva
PPT
Block2 Session2 Presentation
PPT
Introduction to html
PPT
Introduction to html
PPT
IPW 3rd Course - CSS
PPT
Cascading Style Sheets
PPT
Lecture 2 - Comm Lab: Web @ ITP
PDF
TUTORIAL DE CSS 2.0
PPT
Html Presentation Of Web Page Making
PPTX
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
Design Dream
AK css
Understanding THML
Html intro
Html intro
Css Basics
Diva
Block2 Session2 Presentation
Introduction to html
Introduction to html
IPW 3rd Course - CSS
Cascading Style Sheets
Lecture 2 - Comm Lab: Web @ ITP
TUTORIAL DE CSS 2.0
Html Presentation Of Web Page Making
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)

More from Tushar Joshi (7)

PPTX
College Java vs Real Java - Tushar Joshi
PPTX
How Google Search Works By Tushar Joshi
PPT
Open source software by Tushar Joshi
ODP
Technology User Group - Tushar Joshi
PPTX
Working with Passion in daily life by Tushar Joshi Nagpur
ODP
PHPUnit from a developer's perspective
PPTX
Working With Passion by Tushar Joshi
College Java vs Real Java - Tushar Joshi
How Google Search Works By Tushar Joshi
Open source software by Tushar Joshi
Technology User Group - Tushar Joshi
Working with Passion in daily life by Tushar Joshi Nagpur
PHPUnit from a developer's perspective
Working With Passion by Tushar Joshi

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Machine learning based COVID-19 study performance prediction
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Review of recent advances in non-invasive hemoglobin estimation
Machine learning based COVID-19 study performance prediction
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Introduction to Cascading Style Sheets

  • 1. Cascading Style Sheets Tushar Joshi
  • 2. Basic Concepts Redefines a HTML tag. User Agent (often the browser) renders the HTML tag with this modified definition. There are around 50 properties used in CSS H1 { color: blue } Selector Declaration property value Simple CSS Rule
  • 3. Basic Concepts Containment in HTML 1. Using LINK element in the HEAD tag to link to external style sheet. <HTML> <HEAD> <TITLE>title</TITLE> <LINK REL=STYLESHEET TYPE=&quot;text/css“ HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;> <STYLE TYPE=&quot;text/css&quot;> @import url(http://style.com/basic); H1 { color: blue } </STYLE> </HEAD> <BODY> <H1>Headline is blue</H1> <P STYLE=&quot;color: green&quot;> While the paragraph is green. </BODY> </HTML>
  • 4. Basic Concepts Containment in HTML 2. Using STYLE element to write style definitions in the HTML file itself. <HTML> <HEAD> <TITLE>title</TITLE> <LINK REL=STYLESHEET TYPE=&quot;text/css“ HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;> <STYLE TYPE=&quot;text/css&quot;> @import url(http://style.com/basic); H1 { color: blue } </STYLE> </HEAD> <BODY> <H1>Headline is blue</H1> <P STYLE=&quot;color: green&quot;> While the paragraph is green. </BODY> </HTML>
  • 5. Basic Concepts Containment in HTML 3. Importing another style sheet using @import notation. <HTML> <HEAD> <TITLE>title</TITLE> <LINK REL=STYLESHEET TYPE=&quot;text/css“ HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;> <STYLE TYPE=&quot;text/css&quot;> @import url(http://style.com/basic); H1 { color: blue } </STYLE> </HEAD> <BODY> <H1>Headline is blue</H1> <P STYLE=&quot;color: green&quot;> While the paragraph is green. </BODY> </HTML>
  • 6. Basic Concepts Containment in HTML 4. Using style attribute in the HTML element. <HTML> <HEAD> <TITLE>title</TITLE> <LINK REL=STYLESHEET TYPE=&quot;text/css“ HREF=&quot;http://style.com/cool&quot; TITLE=&quot;Cool&quot;> <STYLE TYPE=&quot;text/css&quot;> @import url(http://style.com/basic); H1 { color: blue } </STYLE> </HEAD> <BODY> <H1>Headline is blue</H1> <P STYLE=&quot;color: green&quot;> While the paragraph is green. </BODY> </HTML>
  • 7. Basic Concepts Grouping Selectors can be grouped in comma separated lists Reduce the size of style sheet H1, H2, H3 { font-family: helvetica }
  • 8. Basic Concepts Grouping Declarations can be grouped H1 { font-weight: bold; font-size: 12pt; line-height: 14pt; font-family: helvetica; font-variant: normal; font-style: normal; }
  • 9. Basic Concepts Grouping Some properties have their own grouping syntax H1 { font: bold 12pt/14pt helvetica }
  • 10. Basic Concepts Inheritance <H1>The headline <EM>is</EM> important!</H1> If EM tag has not been defined it takes (inherits) all the styles of enclosing H1 tag. If color of H1 is blue and EM has no defination for color it will be blue.
  • 11. Basic Concepts Inheritance BODY { color: black; background: url(texture.gif) white; } Sets default style for whole document as BODY is the enclosing tag for all. Text color will be black and background will be texture.gif graphics. If graphic file is missing background will be white.
  • 12. Basic Concepts Class as selector Defines “pastoral” as a named style for tag H1 Any elements inside BODY tag can be classed. <HTML> <HEAD> <TITLE>Title</TITLE> <STYLE TYPE=&quot;text/css&quot;> H1.pastoral { color: #00FF00 } </STYLE> </HEAD> <BODY> <H1 CLASS=pastoral>Way too green</H1> </BODY> </HTML>
  • 13. Basic Concepts Class as selector All elements can be addressed by omitting the tag name selector. All elements with class pastoral will be shown in the color defined in the style. <HTML> <HEAD> <TITLE>Title</TITLE> <STYLE TYPE=&quot;text/css&quot;> .pastoral { color: #00FF00 } </STYLE> </HEAD> <BODY> <H1 CLASS=pastoral>Way too green</H1> <P CLASS=pastoral>My Paragraph</P> </BODY> </HTML>
  • 14. Basic Concepts ID as selectors #z97y {letter-spacing: 9am } Name starting with # denoted ID selector. Any element having ID z97y will be applied with this style.
  • 15. Basic Concepts ID as selectors H1#z97y {letter-spacing: 9am } Only H1 tag with ID z97y will be selected for application of this style.
  • 16. Basic Concepts Contextual Selectors H1 EM { color: red } Only EM elements inside H1 tags will be selected to apply color red. H1 EM becomes the pattern to be searched.
  • 17. Basic Concepts Contextual Selectors More Examples DIV P { font: small sans-serif } P element only inside any DIV tag .reddish H1 { color: red } H1 element only inside any tag having class attribute reddish #x78y CODE { background: blue } CODE element only inside the tag having ID x78y DIV.sidenote H1 { font-size: large } H1 element only inside DIV element having class as sidenote
  • 18. Basic Concepts Contextual Selectors Can be grouped together. H1 B, H2 B, H1 EM, H2 EM { color: red } Equivalent to: H1 B { color: red } H2 B { color: red } H1 EM { color: red } H2 EM { color: red }
  • 19. Basic Concepts Comments in style sheets EM { color: red } /* red, really red!! */ Textual comments in CSS style sheets are just like comments for C language. Comments are ignored by CSS parser.
  • 20. Basic Concepts Anchor pseudo-classes Different visual states of anchor tags are represented by pseudo-classes A:link { color: red } /* unvisited link */ A:visited { color: blue } /* visited links */ A:active { color: lime } /* active links */
  • 21. Basic Concepts Anchor pseudo-classes Pseudo classes can be used in conjunction with normal classes. A.alpha:link { color: red } /* unvisited link */ A.beta:visited { color: blue } /* visited links */ A.gamma:active { color: lime } /* active links */ <a class=alpha>Click Me</a>
  • 22. Basic Concepts Anchor pseudo-classes Pseudo classes can be used in contextual selectors All IMG tags only inside A tag will have solid red border. A:link IMG { border: solid red } <A class=alpha><IMG SRC=flower.gif></A>
  • 23. Basic Concepts The Cascade A style sheet designer can combine several (partial) style sheets to reduce redundancy: @import url(http://www.style.org/pastoral); @import url(http://www.style.org/marine); H1 { color: red } /* override imported sheets */ In CSS1, all '@import' statements must occur at the start of a style sheet
  • 24. Basic Concepts The Cascade Author Reader Balance Both readers and authors can influence the presentation through style sheets. Authors explicitly apply style sheets, readers can selectively use them or not. Conflict resolution is based on each style rule having a weight. By default, the weights of the reader's rules are less than the weights of rules in the author's documents.
  • 25. Basic Concepts ‘important’ keyword Weights of the declarations can be increased: H1 { color: black ! important; background: white ! important } P { font-size: 12pt ! important; font-style: italic } In the example above, the first three declarations have increased weight, while the last declaration has normal weight.
  • 26. Basic Concepts Box-oriented formatting model Each formatted element results in one or more rectangular boxes. Elements that have a 'display' value of 'none' are not formatted and will therefore not result in a box. All boxes have a core content area with optional surrounding padding, border and margin areas. Formatting Model
  • 27. Basic Concepts Block Level Elements <STYLE TYPE=&quot;text/css&quot;> UL { background: red; margin: A B C D; padding: E F G H; } LI { color: white; background: blue; /* so text is white on blue */ margin: a b c d; padding: e f g h; } </STYLE> .. <UL> <LI>1st element of list <LI>2nd element of list </UL>
  • 28. Reference Material http://www.w3.org/TR/REC-CSS1 Save the material available for offline reference Use this material as reference, lexicon for properties and their default values CSS has much more to learn and this session should be taken as a starting point.