SlideShare a Scribd company logo
Introduction to CSS
     By Amit Tyagi
What is CSS
• Cascading Style Sheets
• Contains the rules for the presentation of
  HTML.
                +               =

     HTML           CSS             Web Page

• CSS was introduced to keep the
  presentation information separate from
  HTML markup (content).
Before CSS
•   Initially Designers used presentation tags like (FONT, B, BR, TABLE
    etc.) and spacers GIFs to control the design of web pages.
• Any modification in the design of websites
  was a very difficult and boring task , as it
  evolves manually editing every HTML
  page.
Providing support for multiple browsers was a
difficult task.
Sources of Styles
Author (developer) Styles

•    Inline Styles - As inline attribute “style” inside HTML tags
     <div style=“font-weight: bold;”>I am bold</div>

•    Embedded Styles - As embedded style tag with in HTML
     document.
      <html>
         <head>
                  <title>Welcome to Vendio!</title>
                  <style>
                     .footer {
                        width:90%;
                     }
                  </style>
                  -------
      </html>

•    Linked Styles - Inside separate files with .css extension
    <link rel="stylesheet" href=“external.css" type="text/css" />
Sources of Styles(contd.)
• User Style sheets
 This file contains the user created styles .
 [firefox profile folder]/ chrome/userContent-example.css
 is the current user’s style sheet file for the firefox.

• Browser default style sheet
     This file contains default styles for all users of a
     browser
 [firefox folder]/res/html.css is the default style sheet
 file for the firefox.
CSS Selectors
• ID based ( #)
      HTML                              CSS
<div id=“content”>               #content {
  Text                                 width: 200px;
</div>                           }



ID selectors should be used with single elements.
Class based selector
• Class (.)
       HTML                                   CSS
<div class=“big”>                     .big{
   Text                                       width: 200px;
</div>                                }
<div>
   <span class=“big”>some text </span>
</div>


Class based styles can be used by multiple HTML elements.
Tag based selectors
• Tag (Tag name)
       HTML                              CSS
<div>                           DIV {
   Text                                  width: 200px;
</div>                          }
<div>                           SPAN {
   <span>some text </span>               font-size:130%;
</div>                          }
<span>some other text </span>
Grouping
• Multiple selectors can be grouped in a
  single style declaration by using , .
  H1, P , .main {
    font-weight:bold;
  }
Descendant selectors
Descendant selectors are used to select elements that
are descendants (not necessarily children) of another
element in the document tree.
    HTML                            CSS
<div class=“abc”>            DIV.abc P {
  <div>                        font-weight:bold;
    <P>                      }
      Hello there!
    </p>
  </div>
</div>
Child selectors
A child selector is used to select an element that is a
direct child of another element (parent). Child selectors
will not select all descendants, only direct children.
     HTML                              CSS
<div >                          DIV.abc > P {
  <div class=“abc”>               font-weight:bold;
    <P>                         }
       Hello there!
    </p>
  </div>
</div>
Universal selectors
Universal selectors are used to select any
 element.
 * {
    color: blue;
  }
Adjacent sibling selectors
Adjacent sibling selectors will select the
sibling immediately following an element.
DIV.abc + P {
     font-weight: bold;
}
will work for
<div>
   <div class=“abc”>Message</div>
   <P>Hello there!</p>
</div>
Attribute selectors
Attribute selectors selects elements based
upon the attributes present in the HTML
Tags and their value.
  IMG[src="small.gif"] {
      border: 1px solid #000;
  }

will work for
<img src=“small.gif” />
CSS Pseudo-classes
selector:pseudo-class { property: value }
:link
:visited           } Link (A tag) related pseudo classes
:hover
:active

:after
:before
:first-child
:focus
:first-letter
:first-line
:lang
CSS Values
• Words: text-align:center;.
• Numerical values: Numerical values are usually
  followed by a unit type.
  font-size:12px;
  12 is the numerical value and px is the unit type pixels.
  – Absolute Values – in, pc, px, cm, mm, pt
  – Relative Values – em, ex, %

• Color values: color:#336699 or color#369 or
  rgb(255, 255, 255).
Categories of CSS properties
•   Positioning and layout handling related.
•   Background related properties.
•   Font and text related
•   Links related.
•   Lists related.
•   Table related.
Cascade
The CSS cascade assigns a weight
to each style rule. When several
rules apply, the one with the
greatest weight takes precedence.
Order of preference for various
styles:
 – Default browser style sheet
    (weakest)
 – User style sheet
 – Author style sheet
 – Author embedded styles
 – Author inline styles (strongest)
CSS Specificity
Rule 1. CSS File >> Embedded >> Inline

Rule 2. TAG >> class >> ID
Inheritance

• Styles that relate to text and appearance
  are inherited by the descendant
  elements.
• Styles that relate to the appearance of
  boxes created by styling DIVs,
  paragraphs, and other elements, such as
  borders, padding, margins are not
  inherited.
Introduction to CSS
Introduction to CSS
Refrences
• www.w3schools.com
• www.w3.org
• World wide web

More Related Content

What's hot (20)

Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
Mai Moustafa
 
Css3
Css3Css3
Css3
Deepak Mangal
 
Html frames
Html framesHtml frames
Html frames
eShikshak
 
Css selectors
Css selectorsCss selectors
Css selectors
Parth Trivedi
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
Dave Kelly
 
Web Development using HTML & CSS
Web Development using HTML & CSSWeb Development using HTML & CSS
Web Development using HTML & CSS
Shashank Skills Academy
 
WEB I - 01 - Introduction to Web Development
WEB I - 01 - Introduction to Web DevelopmentWEB I - 01 - Introduction to Web Development
WEB I - 01 - Introduction to Web Development
Randy Connolly
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
www.netgains.org
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
Amit Kumar Singh
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 
Bootstrap
BootstrapBootstrap
Bootstrap
Jadson Santos
 
Html presentation
Html presentationHtml presentation
Html presentation
Amber Bhaumik
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
Ravinder Kamboj
 
Learn html Basics
Learn html BasicsLearn html Basics
Learn html Basics
McSoftsis
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
AakankshaR
 
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
Html
HtmlHtml
Html
Bhumika Ratan
 
Presentation on HTML
Presentation on HTMLPresentation on HTML
Presentation on HTML
satvirsandhu9
 

Viewers also liked (7)

CSS ppt
CSS pptCSS ppt
CSS ppt
Sanmuga Nathan
 
Html Ppt
Html PptHtml Ppt
Html Ppt
vijayanit
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
Aashish Ghale
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
vikasgaur31
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
jeroenvdmeer
 
Cookies!
Cookies!Cookies!
Cookies!
kellimccabe
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
vikasgaur31
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
jeroenvdmeer
 
Ad

Similar to Introduction to CSS (20)

introduction to css cascading style sheets
introduction to css cascading style sheetsintroduction to css cascading style sheets
introduction to css cascading style sheets
SherwinSangalang3
 
introductiontohtmlcss-part2-120711042239-phpapp02.ppt
introductiontohtmlcss-part2-120711042239-phpapp02.pptintroductiontohtmlcss-part2-120711042239-phpapp02.ppt
introductiontohtmlcss-part2-120711042239-phpapp02.ppt
SherwinSangalang3
 
css v1 guru
css v1 gurucss v1 guru
css v1 guru
GuruPada Das
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
RasheedMohammad6
 
Artdm171 Week5 Css
Artdm171 Week5 CssArtdm171 Week5 Css
Artdm171 Week5 Css
Gilbert Guerrero
 
Basic css
Basic cssBasic css
Basic css
Gopinath Ambothi
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Hock Leng PUAH
 
UVA MDST 3073 CSS 2012-09-20
UVA MDST 3073 CSS 2012-09-20UVA MDST 3073 CSS 2012-09-20
UVA MDST 3073 CSS 2012-09-20
Rafael Alvarado
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Erin M. Kidwell
 
CSS INTRODUCTION SLIDES WITH HTML CODE.pdf
CSS INTRODUCTION SLIDES WITH HTML CODE.pdfCSS INTRODUCTION SLIDES WITH HTML CODE.pdf
CSS INTRODUCTION SLIDES WITH HTML CODE.pdf
Aasma13
 
Css basics
Css basicsCss basics
Css basics
mirza asif haider
 
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
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
Seble Nigussie
 
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
Thapar Institute
 
Css
CssCss
Css
Jahid Blackrose
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
Stefan Oprea
 
CSS
CSSCSS
CSS
Akila Iroshan
 
2 introduction css
2 introduction css2 introduction css
2 introduction css
Jalpesh Vasa
 
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptxFundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
umoren
 
Css
CssCss
Css
Abhishek Kesharwani
 
introduction to css cascading style sheets
introduction to css cascading style sheetsintroduction to css cascading style sheets
introduction to css cascading style sheets
SherwinSangalang3
 
introductiontohtmlcss-part2-120711042239-phpapp02.ppt
introductiontohtmlcss-part2-120711042239-phpapp02.pptintroductiontohtmlcss-part2-120711042239-phpapp02.ppt
introductiontohtmlcss-part2-120711042239-phpapp02.ppt
SherwinSangalang3
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Hock Leng PUAH
 
UVA MDST 3073 CSS 2012-09-20
UVA MDST 3073 CSS 2012-09-20UVA MDST 3073 CSS 2012-09-20
UVA MDST 3073 CSS 2012-09-20
Rafael Alvarado
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Erin M. Kidwell
 
CSS INTRODUCTION SLIDES WITH HTML CODE.pdf
CSS INTRODUCTION SLIDES WITH HTML CODE.pdfCSS INTRODUCTION SLIDES WITH HTML CODE.pdf
CSS INTRODUCTION SLIDES WITH HTML CODE.pdf
Aasma13
 
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 technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
Stefan Oprea
 
2 introduction css
2 introduction css2 introduction css
2 introduction css
Jalpesh Vasa
 
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptxFundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
Fundamental of Web Development Tutorials-CSS by PINFO Technologies.pptx
umoren
 
Ad

Recently uploaded (20)

How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 

Introduction to CSS

  • 1. Introduction to CSS By Amit Tyagi
  • 2. What is CSS • Cascading Style Sheets • Contains the rules for the presentation of HTML. + = HTML CSS Web Page • CSS was introduced to keep the presentation information separate from HTML markup (content).
  • 3. Before CSS • Initially Designers used presentation tags like (FONT, B, BR, TABLE etc.) and spacers GIFs to control the design of web pages.
  • 4. • Any modification in the design of websites was a very difficult and boring task , as it evolves manually editing every HTML page.
  • 5. Providing support for multiple browsers was a difficult task.
  • 6. Sources of Styles Author (developer) Styles • Inline Styles - As inline attribute “style” inside HTML tags <div style=“font-weight: bold;”>I am bold</div> • Embedded Styles - As embedded style tag with in HTML document. <html> <head> <title>Welcome to Vendio!</title> <style> .footer { width:90%; } </style> ------- </html> • Linked Styles - Inside separate files with .css extension <link rel="stylesheet" href=“external.css" type="text/css" />
  • 7. Sources of Styles(contd.) • User Style sheets This file contains the user created styles . [firefox profile folder]/ chrome/userContent-example.css is the current user’s style sheet file for the firefox. • Browser default style sheet This file contains default styles for all users of a browser [firefox folder]/res/html.css is the default style sheet file for the firefox.
  • 8. CSS Selectors • ID based ( #) HTML CSS <div id=“content”> #content { Text width: 200px; </div> } ID selectors should be used with single elements.
  • 9. Class based selector • Class (.) HTML CSS <div class=“big”> .big{ Text width: 200px; </div> } <div> <span class=“big”>some text </span> </div> Class based styles can be used by multiple HTML elements.
  • 10. Tag based selectors • Tag (Tag name) HTML CSS <div> DIV { Text width: 200px; </div> } <div> SPAN { <span>some text </span> font-size:130%; </div> } <span>some other text </span>
  • 11. Grouping • Multiple selectors can be grouped in a single style declaration by using , . H1, P , .main { font-weight:bold; }
  • 12. Descendant selectors Descendant selectors are used to select elements that are descendants (not necessarily children) of another element in the document tree. HTML CSS <div class=“abc”> DIV.abc P { <div> font-weight:bold; <P> } Hello there! </p> </div> </div>
  • 13. Child selectors A child selector is used to select an element that is a direct child of another element (parent). Child selectors will not select all descendants, only direct children. HTML CSS <div > DIV.abc > P { <div class=“abc”> font-weight:bold; <P> } Hello there! </p> </div> </div>
  • 14. Universal selectors Universal selectors are used to select any element. * { color: blue; }
  • 15. Adjacent sibling selectors Adjacent sibling selectors will select the sibling immediately following an element. DIV.abc + P { font-weight: bold; } will work for <div> <div class=“abc”>Message</div> <P>Hello there!</p> </div>
  • 16. Attribute selectors Attribute selectors selects elements based upon the attributes present in the HTML Tags and their value. IMG[src="small.gif"] { border: 1px solid #000; } will work for <img src=“small.gif” />
  • 17. CSS Pseudo-classes selector:pseudo-class { property: value } :link :visited } Link (A tag) related pseudo classes :hover :active :after :before :first-child :focus :first-letter :first-line :lang
  • 18. CSS Values • Words: text-align:center;. • Numerical values: Numerical values are usually followed by a unit type. font-size:12px; 12 is the numerical value and px is the unit type pixels. – Absolute Values – in, pc, px, cm, mm, pt – Relative Values – em, ex, % • Color values: color:#336699 or color#369 or rgb(255, 255, 255).
  • 19. Categories of CSS properties • Positioning and layout handling related. • Background related properties. • Font and text related • Links related. • Lists related. • Table related.
  • 20. Cascade The CSS cascade assigns a weight to each style rule. When several rules apply, the one with the greatest weight takes precedence. Order of preference for various styles: – Default browser style sheet (weakest) – User style sheet – Author style sheet – Author embedded styles – Author inline styles (strongest)
  • 21. CSS Specificity Rule 1. CSS File >> Embedded >> Inline Rule 2. TAG >> class >> ID
  • 22. Inheritance • Styles that relate to text and appearance are inherited by the descendant elements. • Styles that relate to the appearance of boxes created by styling DIVs, paragraphs, and other elements, such as borders, padding, margins are not inherited.