SlideShare a Scribd company logo
Module-3
Cascading Style
Sheets (CSS)
Module 3:
Cascading Style Sheets (CSS)
Introduction
• The CSS1 specification was developed in 1996
• CSS2 was released in 1998
• CSS3 is on its way
• CSSs provide the means to control and change presentation of
HTML documents
• CSS is not technically HTML, but can be embedded in HTML
documents
• Style sheets allow you to impose a standard style on a whole
document, or even a whole collection of documents
• Style is specified for a tag by the values of its properties
Levels of Style Sheets
• There are three levels of style sheets
– Inline - specified for a specific occurrence of a tag and apply only to
that tag
– This is fine-grain style, which defeats the purpose of style sheets -
uniform style
– Document-level style sheets - apply to the whole document in which
they appear
– External style sheets - can be applied to any number of documents
• When more than one style sheet applies to a specific tag in a
document, the lowest level style sheet has precedence
– In a sense, the browser searches for a style property spec, starting
with inline, until it finds one (or there isn’t one)
Levels of Style Sheets (continued)
• Inline style sheets appear in the tag itself
• Document-level style sheets appear in the
head of the document
• External style sheets are in separate files,
potentially on any server on the Internet
– Written as text files with the MIME type text/css
Introduction
Cascading Style Sheets (CSS) concepts and CSS basic
syntax.
• Cascading Style Sheets is a style sheet language
used for describing the presentation of a
document written in a markup language such as
HTML or XML.
• The W3C’s philosophy in terms of how HTML and
CSS should fit together is (1) use HTML elements
to specify a web page’s content, and (2) use CSS to
specify a web page’s appearance.
• There are lots and lots of CSS properties that
CSS Rules
CSS Rule Sets
• A CSS rule set contains one or more selectors
and one or more declarations.
• The selector(s), which in this example is h1 , points
to an HTML element.
• The declaration(s), which in this example are
color: blue and text-align: center style the element
with a property and value.
CSS Rules
• The selector points to the HTML element to style (h1).
• The declaration block (in curly braces) contains one or more
declarations separated by semicolons.
• Each declaration includes a CSS property name and a value,
separated by a colon.
CSS Rules
Selector
Declaration of
Property:
value
CSS Rules
Example for Selector and Declaration: Tree
Poem web page
CSS Rules
Example for Selector and Declaration: Tree
Poem web page
In the Tree Poem web page, the
• * {text-align: center;} rule causes the elements that contain
text to be centered.
• The hr element does not contain text, so it’s not affected by
the text-align property and hr elements are centered by
default.
• The hr {width: 50%;} rule causes the horizontal line to
render with a width that’s 50% of the web page body’s
width.
• The h2, p {font-style: italic; color: blue;} rule causes the
heading and paragraph elements to be italicized and blue.
CSS Syntax and style
CSS Syntax
The style container positioned at the bottom of the web
page’s head container. In the style start tag, it’s legal to
include a type attribute with a value of "text/css", like
this
CSS Syntax and style
CSS Syntax
In the Tree Poem web page, the type attribute is omitted.
Currently, text/css is the only legal value for the type
attribute, and it’s the default value for the type attribute.
Google’s Style Guide, which covers both HTML and CSS,
recommends that you reduce the size of your web page file
by omitting the type attribute.
CSS Syntax and style
CSS Style
Style is used to style and layout the web pages — for
example, to alter the font, color, size, and spacing of
your content, split it into multiple columns, or add
animations and other decorative features.
CSS Syntax and style
CSS Style
when there is block formatting for multi-line container
elements, the start tag and end tag are aligned at the
left, and interior lines are indented.
If there is a long CSS (at least two
or three property-value pairs), use
block formatting like this
CSS Class Selectors
Class selector
• A CSS class is an attribute used to define a group of
HTML elements in order to apply unique styling and
formatting to those elements with CSS.
• Use a dot operator(.) followed by the class name in a
style block.
• Use a bracket called a declaration block that contains the
property to stylize the element, such as text color or text
size. CSS Classes will help to stylize HTML elements
quickly
• Example: .class name
CSS Class Selectors
The two types of normal selectors are selectors and the
universal selector.
The third type of CSS selector—a class selector
The dot thing (.red in this example) is called a class selector because its
purpose is to select elements that have a particular value for their class
attribute. So the class selector rule would select/match the following element
because it has a class attribute with a value of red:
<p class= red> a class selector that select elements that have a
particular value for their class attribute</p> In applying the class selector
rule to this element, the quote gets displayed with a tomato background
color
CSS Class Selectors
Class selector:
The three CSS rules with their class selectors .red,
.white, and .blue
<q> tag defines a
short quotation
CSS Class Selectors
Class selector:
The three CSS rules with their class selectors .red,
.white, and .blue
CSS Class Selectors
Class Selectors with Element Type Prefixes
It is used apply a CSS rule to any element whose one of the classes
matches specified prefix. When the same class name is to be used for
multiple elements, but each with a different style, you can prefix the
dot with the HTML element name.
element-type.class-value {property1: value;
property2: value;}
CSS Class Selectors
Class Selectors with * Prefixes
• Instead of prefacing a class selector with an element type, as an
alternative, you can preface a class selector with an *. Because *
is the universal selector, it matches all elements. Therefore, the
following CSS rule is equivalent to a standard class selector rule
(with no prefix)
*.class-value {property1: value;
property2: value;}
Example: *.big-warning {font-size: x-large;
color: red;
• It would match all elements in the web page that have a class
attribute value of big-warning, and it would display those
elements with extra-large red font.
• CSS property names follow the same coding convention as developer-
defined class attribute values—if there are multiple words, use hyphens
to separate the words (e.g., font-size). CSS property values usually follow
the same use-hyphens-to-separate-multiple-words coding convention.
CSS ID Selectors
• An ID selector is similar to a class selector in that it relies on
an element attribute value in searching for element matches.
• An ID selector uses an element’s id attribute (as opposed to a
class selector, which uses an element’s class attribute).
• A significant feature of an id attribute is that its value must be
unique within a particular web page. That’s different from a
class attribute’s value, which does not have to be unique within
a particular web page.
• The ID selector’s unique-value feature means that an ID
selector’s CSS rule matches only one element on a web page.
• ID selectors are an important part of CSS.
CSS ID Selectors
To match an element with an id attribute, an ID selector rule is
needed, and the syntax is
The syntax is the same as for a class selector rule, except that you
use a pound sign (#) instead of a dot (.), and use an id attribute
value instead of a class attribute value.
#lizards-lounge {color: green;}
<h1 id="lizards-lounge">Lizards Lounge</h1>
CSS ID Selectors
To match an element with an id attribute, an ID selector rule iss
needed, and the syntax is
CSS * Selector
The * selector selects all elements.
The * selector can also select all elements inside
another element
Syntax :
* {
css declarations;
}
Example:
* {
background-color: yellow;
}

More Related Content

Similar to Cascading style sheets, Introduction to web programming

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

Similar to Cascading style sheets, Introduction to web programming (20)

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
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Intro to css
Intro to cssIntro to css
Intro to css
 
CSS Basics (Cascading Style Sheet)
CSS Basics (Cascading Style Sheet)CSS Basics (Cascading Style Sheet)
CSS Basics (Cascading Style Sheet)
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
Css
CssCss
Css
 
Css1
Css1Css1
Css1
 
Web Development - Lecture 5
Web Development - Lecture 5Web Development - Lecture 5
Web Development - Lecture 5
 
CSS - LinkedIn
CSS - LinkedInCSS - LinkedIn
CSS - LinkedIn
 
CASCADING STYLE SHEETS (CSS).pptx
CASCADING STYLE SHEETS (CSS).pptxCASCADING STYLE SHEETS (CSS).pptx
CASCADING STYLE SHEETS (CSS).pptx
 
Web Concepts_Introduction to presentation.pptx
Web Concepts_Introduction to presentation.pptxWeb Concepts_Introduction to presentation.pptx
Web Concepts_Introduction to presentation.pptx
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptx
 
Css
CssCss
Css
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
CSS tutorial chapter 1
CSS tutorial chapter 1CSS tutorial chapter 1
CSS tutorial chapter 1
 
CSS Basics part One
CSS Basics part OneCSS Basics part One
CSS Basics part One
 
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
 
Web technology Unit-II Part-C
Web technology Unit-II Part-CWeb technology Unit-II Part-C
Web technology Unit-II Part-C
 

Recently uploaded

Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 

Recently uploaded (20)

The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
Online book store management system project.pdf
Online book store management system project.pdfOnline book store management system project.pdf
Online book store management system project.pdf
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 

Cascading style sheets, Introduction to web programming

  • 3. Introduction • The CSS1 specification was developed in 1996 • CSS2 was released in 1998 • CSS3 is on its way • CSSs provide the means to control and change presentation of HTML documents • CSS is not technically HTML, but can be embedded in HTML documents • Style sheets allow you to impose a standard style on a whole document, or even a whole collection of documents • Style is specified for a tag by the values of its properties
  • 4. Levels of Style Sheets • There are three levels of style sheets – Inline - specified for a specific occurrence of a tag and apply only to that tag – This is fine-grain style, which defeats the purpose of style sheets - uniform style – Document-level style sheets - apply to the whole document in which they appear – External style sheets - can be applied to any number of documents • When more than one style sheet applies to a specific tag in a document, the lowest level style sheet has precedence – In a sense, the browser searches for a style property spec, starting with inline, until it finds one (or there isn’t one)
  • 5. Levels of Style Sheets (continued) • Inline style sheets appear in the tag itself • Document-level style sheets appear in the head of the document • External style sheets are in separate files, potentially on any server on the Internet – Written as text files with the MIME type text/css
  • 6. Introduction Cascading Style Sheets (CSS) concepts and CSS basic syntax. • Cascading Style Sheets is a style sheet language used for describing the presentation of a document written in a markup language such as HTML or XML. • The W3C’s philosophy in terms of how HTML and CSS should fit together is (1) use HTML elements to specify a web page’s content, and (2) use CSS to specify a web page’s appearance. • There are lots and lots of CSS properties that
  • 7. CSS Rules CSS Rule Sets • A CSS rule set contains one or more selectors and one or more declarations. • The selector(s), which in this example is h1 , points to an HTML element. • The declaration(s), which in this example are color: blue and text-align: center style the element with a property and value.
  • 8. CSS Rules • The selector points to the HTML element to style (h1). • The declaration block (in curly braces) contains one or more declarations separated by semicolons. • Each declaration includes a CSS property name and a value, separated by a colon.
  • 10. CSS Rules Example for Selector and Declaration: Tree Poem web page
  • 11. CSS Rules Example for Selector and Declaration: Tree Poem web page In the Tree Poem web page, the • * {text-align: center;} rule causes the elements that contain text to be centered. • The hr element does not contain text, so it’s not affected by the text-align property and hr elements are centered by default. • The hr {width: 50%;} rule causes the horizontal line to render with a width that’s 50% of the web page body’s width. • The h2, p {font-style: italic; color: blue;} rule causes the heading and paragraph elements to be italicized and blue.
  • 12. CSS Syntax and style CSS Syntax The style container positioned at the bottom of the web page’s head container. In the style start tag, it’s legal to include a type attribute with a value of "text/css", like this
  • 13. CSS Syntax and style CSS Syntax In the Tree Poem web page, the type attribute is omitted. Currently, text/css is the only legal value for the type attribute, and it’s the default value for the type attribute. Google’s Style Guide, which covers both HTML and CSS, recommends that you reduce the size of your web page file by omitting the type attribute.
  • 14. CSS Syntax and style CSS Style Style is used to style and layout the web pages — for example, to alter the font, color, size, and spacing of your content, split it into multiple columns, or add animations and other decorative features.
  • 15. CSS Syntax and style CSS Style when there is block formatting for multi-line container elements, the start tag and end tag are aligned at the left, and interior lines are indented. If there is a long CSS (at least two or three property-value pairs), use block formatting like this
  • 16. CSS Class Selectors Class selector • A CSS class is an attribute used to define a group of HTML elements in order to apply unique styling and formatting to those elements with CSS. • Use a dot operator(.) followed by the class name in a style block. • Use a bracket called a declaration block that contains the property to stylize the element, such as text color or text size. CSS Classes will help to stylize HTML elements quickly • Example: .class name
  • 17. CSS Class Selectors The two types of normal selectors are selectors and the universal selector. The third type of CSS selector—a class selector The dot thing (.red in this example) is called a class selector because its purpose is to select elements that have a particular value for their class attribute. So the class selector rule would select/match the following element because it has a class attribute with a value of red: <p class= red> a class selector that select elements that have a particular value for their class attribute</p> In applying the class selector rule to this element, the quote gets displayed with a tomato background color
  • 18. CSS Class Selectors Class selector: The three CSS rules with their class selectors .red, .white, and .blue <q> tag defines a short quotation
  • 19. CSS Class Selectors Class selector: The three CSS rules with their class selectors .red, .white, and .blue
  • 20. CSS Class Selectors Class Selectors with Element Type Prefixes It is used apply a CSS rule to any element whose one of the classes matches specified prefix. When the same class name is to be used for multiple elements, but each with a different style, you can prefix the dot with the HTML element name. element-type.class-value {property1: value; property2: value;}
  • 21. CSS Class Selectors Class Selectors with * Prefixes • Instead of prefacing a class selector with an element type, as an alternative, you can preface a class selector with an *. Because * is the universal selector, it matches all elements. Therefore, the following CSS rule is equivalent to a standard class selector rule (with no prefix) *.class-value {property1: value; property2: value;} Example: *.big-warning {font-size: x-large; color: red; • It would match all elements in the web page that have a class attribute value of big-warning, and it would display those elements with extra-large red font. • CSS property names follow the same coding convention as developer- defined class attribute values—if there are multiple words, use hyphens to separate the words (e.g., font-size). CSS property values usually follow the same use-hyphens-to-separate-multiple-words coding convention.
  • 22. CSS ID Selectors • An ID selector is similar to a class selector in that it relies on an element attribute value in searching for element matches. • An ID selector uses an element’s id attribute (as opposed to a class selector, which uses an element’s class attribute). • A significant feature of an id attribute is that its value must be unique within a particular web page. That’s different from a class attribute’s value, which does not have to be unique within a particular web page. • The ID selector’s unique-value feature means that an ID selector’s CSS rule matches only one element on a web page. • ID selectors are an important part of CSS.
  • 23. CSS ID Selectors To match an element with an id attribute, an ID selector rule is needed, and the syntax is The syntax is the same as for a class selector rule, except that you use a pound sign (#) instead of a dot (.), and use an id attribute value instead of a class attribute value. #lizards-lounge {color: green;} <h1 id="lizards-lounge">Lizards Lounge</h1>
  • 24. CSS ID Selectors To match an element with an id attribute, an ID selector rule iss needed, and the syntax is
  • 25. CSS * Selector The * selector selects all elements. The * selector can also select all elements inside another element Syntax : * { css declarations; } Example: * { background-color: yellow; }