SlideShare a Scribd company logo
1 of 27
Download to read offline
CSS
• Cascading Style Sheets, fondly referred to as CSS,
is a simple design language intended to simplify
the process of making web pages presentable.
• CSS handles the look and feel part of a web page.
Using CSS, you can control the color of the text,
the style of fonts, the spacing between
paragraphs, how columns are sized and laid out,
what background images or colors are used, as
well as a variety of other effects.
• CSS is easy to learn and understand but it
provides powerful control over the presentation
of an HTML document.
Advantages of CSS
• CSS saves time - You can write CSS once and then
reuse same sheet in multiple HTML pages. You
can define a style for each HTML element and
apply it to as many Web pages as you want.
• Pages load faster - If you are using CSS, you do
not need to write HTML tag attributes every time.
Just write one CSS rule of a tag and apply to all
the occurrences of that tag. So less code means
faster download times.
• Easy maintenance - To make a global change,
simply change the style, and all elements in all
the web pages will be updated automatically.
• Superior styles to HTML - CSS has a much wider
array of attributes than HTML so you can give far
better look to your HTML page in comparison of
HTML attributes.
• Multiple Device Compatibility - Style sheets
allow content to be optimized for more than one
type of device. By using the same HTML
document, different versions of a website can be
presented for handheld devices such as PDAs and
cell phones or for printing.
• Global web standards - Now HTML attributes are
being deprecated and it is being recommended to
use CSS.
Who Creates and Maintains CSS?
• CSS is created and maintained through a
group of people within the W3C called the CSS
Working Group. The CSS Working Group
creates documents called specifications.
When a specification has been discussed and
officially ratified by W3C members, it becomes
a recommendation.
NOTE: The World Wide Web Consortium, or
W3C is a group that makes recommendations
about how the Internet works and how it
should evolve
CSS Versions
• Cascading Style Sheets, level 1 (CSS1) was came
out of W3C as a recommendation in December
1996. This version describes the CSS language as
well as a simple visual formatting model for all
the HTML tags.
• CSS2 was became a W3C recommendation in
May 1998 and builds on CSS1. This version adds
support for media-specific style sheets e.g.
printers and aural devices, downloadable fonts,
element positioning and tables.
• The earliest CSS 3 drafts were published in June
1999.
CSS Syntax – Selectors
A CSS comprises of style rules that are interpreted
by the browser and then applied to the
corresponding elements in your document. A
style rule is made of three parts:
• Selector: A selector is an HTML tag at which style
will be applied. This could be any tag like <h1> or
<table> etc.
• Property: A property is a type of attribute of
HTML tag. Put simply, all the HTML attributes are
converted into CSS properties. They could
be color or border etc.
• Value: Values are assigned to properties. For
example color property can have value
either red or #F1F1F1 etc.
selector { property: value }
Example: You can define a table border as
follows:
table{ border :1px}
CSS Inclusion - Associating Styles
There are four ways to associate styles with your
HTML document. Most commonly used
methods are inline CSS and External CSS.
Embedded CSS
Inline CSS
External CSS
Imported CSS
Embedded CSS
• You can put your CSS rules into an HTML
document using the <style> element. This tag is
placed inside <head>...</head> tags. Rules
defined using this syntax will be applied to all
the elements available in the document.
Syntax:
<head>
<style type="text/css" media="...">
Style Rules............
</style>
</head>
Inline CSS
• You can use style attribute of any HTML
element to define style rules. These rules will
be applied to that element only. Here is the
generic syntax:
• <element style="...style rules....">
<h1 style ="color:#36C;"> This is inline CSS</h1>
External CSS
• The <link> element can be used to include an
external stylesheet file in your HTML
document.
• An external style sheet is a separate text file
with .css extension. You define all the Style
rules within this text file and then you can
include this file in any HTML document using
<link> element.
<head><link rel=”stylesheet” type="text/css"
href="..." media="..." /></head>
Imported CSS
• @import is used to import an external
stylesheet in a manner similar to the <link>
element.
<head>
<style>
@import url("a.css");
</style>
</head>
The Type Selectors
In this type simply apply selector name and set
the attribute value you have to change.
h1 { color: #36CFFF; }
The Descendant Selectors
• Suppose you want to apply a style rule to a
particular element only when it lies inside a
particular element.
• ul em { color: #000000; }
The Class Selectors
• You can define style rules based on the class
attribute of the elements. All the elements
having that class will be formatted according
to the defined rule.
• .black { color: #000000; }
• <h1 class="black">Hello Welcome </h1>
The ID Selectors
• You can define style rules based on the id
attribute of the elements. All the elements
having that id will be formatted according to
the defined rule.
• #black { color: #000000; }
• <h1 id="mycolor">Hello Welcome </h1>
The Child Selectors
• You have seen descendant selectors. There is one
more type of selectors which is very similar to
descendants but have different functionality.
• body > p { color: #000000; }
• This rule will render all the paragraphs in black if
they are direct child of <body> element. Other
paragraphs put inside other elements like <div>
or <td> etc. would not have any effect of this rule.
Multiple Style Rules
• You may need to define multiple style rules for
a single element.
h1 {color: #36C;
font-weight: normal;
letter-spacing: .4px;
margin-bottom: 1px;
text-transform: lowercase;
}
Grouping Selectors
• You can apply a style to many selectors if you
like. Just separate the selectors with a comma
as given in the following example:
h1, h2, h3 {color: #36C;font-weight:
normal;letter-spacing: .4em;margin-bottom:
1em;text-transform: lowercase;}
CSS Rules Overriding
• Any inline style sheet takes highest priority. So
it will override any rule defined in
<style>...</style> tags or rules defined in any
external style sheet file.
• Any rule defined in <style>...</style> tags will
override rules defined in any external style
sheet file.
• Any rule defined in external style sheet file
takes lowest priority and rules defined in this
file will be applied only when above two rules
are not applicable.
CSS - Measurement Units
CSS - Colors
Setting Backgrounds using CSS
• The background-color property is used to set the
background color of an element.
• The background-image property is used to set the
background image of an element.
• The background-repeat property is used to control
the repetition of an image in the background.
• The background-position property is used to control
the position of an image in the background.
• The background-attachment property is used to
control the scrolling of an image in the background.
• The background property is used as shorthand to
specify a number of other background properties
• <p style="background-color:yellow;“>
• <table style="background-
image:url(/images/pattern1.gif);">
• <table style="background-
image:url(/images/pattern1.gif);
• background-repeat: repeat;">
• <table style="background-
image:url(/images/pattern1.gif);
• background-repeat: repeat-y;">
Setting Fonts using CSS
• The font-family property is used to change the
face of a font.
• The font-style property is used to make a font
italic or oblique.
• The font-variant property is used to create a
small-caps effect.
• The font-weight property is used to increase or
decrease how bold or light a font appears.
• The font-size property is used to increase or
decrease the size of a font.
• The font property is used as shorthand to specify
a number of other font properties.
<p style="font-family:georgia,garamond,serif;">
This text is rendered in either georgia, garamond, or the
default
serif font depending on which font you have at your system.
</p>
<p style="font-style:italic;">
This text will be rendered in italic style
</p>
<p style="font-variant:small-caps;">
This text will be rendered as small caps
</p>
<p style="font-weight:bold;">
This font is bold.
</p>
<p style="font-weight:bolder;">
This font is bolder.
</p>
<p style="font-weight:900;">
This font is 900 weight.
</p>
<p style="font-size:20px;">
This font size is 20 pixels
</p>
<p style="font-size:small;">
This font size is small
</p>
<p style="font-size:large;">
This font size is large
</p>
<p style="font:italic small-caps bold 15px greorgia;">
Applying all the properties on the text at once.
</p>

More Related Content

What's hot

Javascript operators
Javascript operatorsJavascript operators
Javascript operators
Mohit Rana
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
Krazy Koder
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68
myrajendra
 
Xml web services
Xml web servicesXml web services
Xml web services
Raghu nath
 

What's hot (20)

Get method and post method
Get method and post methodGet method and post method
Get method and post method
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Unit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascriptUnit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascript
 
android menus
android menusandroid menus
android menus
 
Ch21 windows 10
Ch21 windows 10Ch21 windows 10
Ch21 windows 10
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operators
 
Html5 for mobiles
Html5 for mobilesHtml5 for mobiles
Html5 for mobiles
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Cohen Sutherland Line Clipping Algorithm Example
Cohen Sutherland Line Clipping Algorithm ExampleCohen Sutherland Line Clipping Algorithm Example
Cohen Sutherland Line Clipping Algorithm Example
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68
 
Xml web services
Xml web servicesXml web services
Xml web services
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
jQuery
jQueryjQuery
jQuery
 
Html presentation
Html presentationHtml presentation
Html presentation
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and Tables
 

Viewers also liked (18)

Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
Qo s rsvp......
Qo s rsvp......Qo s rsvp......
Qo s rsvp......
 
Xml3
Xml3Xml3
Xml3
 
2
22
2
 
Unit 1
Unit 1 Unit 1
Unit 1
 
Html
HtmlHtml
Html
 
2
22
2
 
Html forms
Html formsHtml forms
Html forms
 
2 simulation in aodv and dsr
2 simulation in aodv and dsr2 simulation in aodv and dsr
2 simulation in aodv and dsr
 
Html3
Html3Html3
Html3
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Icmp
IcmpIcmp
Icmp
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
Flow control
Flow controlFlow control
Flow control
 
Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1 Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1
 
Xml
XmlXml
Xml
 
Dss digital signature standard and dsa algorithm
Dss  digital signature standard and dsa algorithmDss  digital signature standard and dsa algorithm
Dss digital signature standard and dsa algorithm
 

Similar to Css

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
 
Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...
JebaRaj26
 

Similar to Css (20)

uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
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
 
Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...
 
Unit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxUnit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptx
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Kick start @ css
Kick start @ cssKick start @ css
Kick start @ css
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
DHTML
DHTMLDHTML
DHTML
 
BITM3730 9-19.pptx
BITM3730 9-19.pptxBITM3730 9-19.pptx
BITM3730 9-19.pptx
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptx
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
 
Responsive web design with html5 and css3
Responsive web design with html5 and css3Responsive web design with html5 and css3
Responsive web design with html5 and css3
 
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
 
Cascading Style Sheets By Mukesh
Cascading Style Sheets By MukeshCascading Style Sheets By Mukesh
Cascading Style Sheets By Mukesh
 
DW unit 3.pptx
DW unit 3.pptxDW unit 3.pptx
DW unit 3.pptx
 
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
 

More from Abhishek Kesharwani

More from Abhishek Kesharwani (20)

uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Unit 1 web technology uptu slide
Unit 1 web technology uptu slideUnit 1 web technology uptu slide
Unit 1 web technology uptu slide
 
Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1 Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1
 
Unit1 2
Unit1 2 Unit1 2
Unit1 2
 
Mtech syllabus computer science uptu
Mtech syllabus computer science uptu Mtech syllabus computer science uptu
Mtech syllabus computer science uptu
 
Wi max tutorial
Wi max tutorialWi max tutorial
Wi max tutorial
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Tcp traffic control and red ecn
Tcp traffic control and red ecnTcp traffic control and red ecn
Tcp traffic control and red ecn
 
Schedulling
SchedullingSchedulling
Schedulling
 
Scheduling
SchedulingScheduling
Scheduling
 
Rsa example
Rsa exampleRsa example
Rsa example
 
Routers and planes (1)
Routers and planes (1)Routers and planes (1)
Routers and planes (1)
 

Css

  • 1. CSS • Cascading Style Sheets, fondly referred to as CSS, is a simple design language intended to simplify the process of making web pages presentable. • CSS handles the look and feel part of a web page. Using CSS, you can control the color of the text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what background images or colors are used, as well as a variety of other effects. • CSS is easy to learn and understand but it provides powerful control over the presentation of an HTML document.
  • 2. Advantages of CSS • CSS saves time - You can write CSS once and then reuse same sheet in multiple HTML pages. You can define a style for each HTML element and apply it to as many Web pages as you want. • Pages load faster - If you are using CSS, you do not need to write HTML tag attributes every time. Just write one CSS rule of a tag and apply to all the occurrences of that tag. So less code means faster download times. • Easy maintenance - To make a global change, simply change the style, and all elements in all the web pages will be updated automatically.
  • 3. • Superior styles to HTML - CSS has a much wider array of attributes than HTML so you can give far better look to your HTML page in comparison of HTML attributes. • Multiple Device Compatibility - Style sheets allow content to be optimized for more than one type of device. By using the same HTML document, different versions of a website can be presented for handheld devices such as PDAs and cell phones or for printing. • Global web standards - Now HTML attributes are being deprecated and it is being recommended to use CSS.
  • 4. Who Creates and Maintains CSS? • CSS is created and maintained through a group of people within the W3C called the CSS Working Group. The CSS Working Group creates documents called specifications. When a specification has been discussed and officially ratified by W3C members, it becomes a recommendation. NOTE: The World Wide Web Consortium, or W3C is a group that makes recommendations about how the Internet works and how it should evolve
  • 5. CSS Versions • Cascading Style Sheets, level 1 (CSS1) was came out of W3C as a recommendation in December 1996. This version describes the CSS language as well as a simple visual formatting model for all the HTML tags. • CSS2 was became a W3C recommendation in May 1998 and builds on CSS1. This version adds support for media-specific style sheets e.g. printers and aural devices, downloadable fonts, element positioning and tables. • The earliest CSS 3 drafts were published in June 1999.
  • 6. CSS Syntax – Selectors A CSS comprises of style rules that are interpreted by the browser and then applied to the corresponding elements in your document. A style rule is made of three parts: • Selector: A selector is an HTML tag at which style will be applied. This could be any tag like <h1> or <table> etc. • Property: A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color or border etc. • Value: Values are assigned to properties. For example color property can have value either red or #F1F1F1 etc.
  • 7. selector { property: value } Example: You can define a table border as follows: table{ border :1px}
  • 8. CSS Inclusion - Associating Styles There are four ways to associate styles with your HTML document. Most commonly used methods are inline CSS and External CSS. Embedded CSS Inline CSS External CSS Imported CSS
  • 9. Embedded CSS • You can put your CSS rules into an HTML document using the <style> element. This tag is placed inside <head>...</head> tags. Rules defined using this syntax will be applied to all the elements available in the document. Syntax: <head> <style type="text/css" media="..."> Style Rules............ </style> </head>
  • 10. Inline CSS • You can use style attribute of any HTML element to define style rules. These rules will be applied to that element only. Here is the generic syntax: • <element style="...style rules...."> <h1 style ="color:#36C;"> This is inline CSS</h1>
  • 11. External CSS • The <link> element can be used to include an external stylesheet file in your HTML document. • An external style sheet is a separate text file with .css extension. You define all the Style rules within this text file and then you can include this file in any HTML document using <link> element. <head><link rel=”stylesheet” type="text/css" href="..." media="..." /></head>
  • 12. Imported CSS • @import is used to import an external stylesheet in a manner similar to the <link> element. <head> <style> @import url("a.css"); </style> </head>
  • 13. The Type Selectors In this type simply apply selector name and set the attribute value you have to change. h1 { color: #36CFFF; }
  • 14. The Descendant Selectors • Suppose you want to apply a style rule to a particular element only when it lies inside a particular element. • ul em { color: #000000; }
  • 15. The Class Selectors • You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule. • .black { color: #000000; } • <h1 class="black">Hello Welcome </h1>
  • 16. The ID Selectors • You can define style rules based on the id attribute of the elements. All the elements having that id will be formatted according to the defined rule. • #black { color: #000000; } • <h1 id="mycolor">Hello Welcome </h1>
  • 17. The Child Selectors • You have seen descendant selectors. There is one more type of selectors which is very similar to descendants but have different functionality. • body > p { color: #000000; } • This rule will render all the paragraphs in black if they are direct child of <body> element. Other paragraphs put inside other elements like <div> or <td> etc. would not have any effect of this rule.
  • 18. Multiple Style Rules • You may need to define multiple style rules for a single element. h1 {color: #36C; font-weight: normal; letter-spacing: .4px; margin-bottom: 1px; text-transform: lowercase; }
  • 19. Grouping Selectors • You can apply a style to many selectors if you like. Just separate the selectors with a comma as given in the following example: h1, h2, h3 {color: #36C;font-weight: normal;letter-spacing: .4em;margin-bottom: 1em;text-transform: lowercase;}
  • 20. CSS Rules Overriding • Any inline style sheet takes highest priority. So it will override any rule defined in <style>...</style> tags or rules defined in any external style sheet file. • Any rule defined in <style>...</style> tags will override rules defined in any external style sheet file. • Any rule defined in external style sheet file takes lowest priority and rules defined in this file will be applied only when above two rules are not applicable.
  • 23. Setting Backgrounds using CSS • The background-color property is used to set the background color of an element. • The background-image property is used to set the background image of an element. • The background-repeat property is used to control the repetition of an image in the background. • The background-position property is used to control the position of an image in the background. • The background-attachment property is used to control the scrolling of an image in the background. • The background property is used as shorthand to specify a number of other background properties
  • 24. • <p style="background-color:yellow;“> • <table style="background- image:url(/images/pattern1.gif);"> • <table style="background- image:url(/images/pattern1.gif); • background-repeat: repeat;"> • <table style="background- image:url(/images/pattern1.gif); • background-repeat: repeat-y;">
  • 25. Setting Fonts using CSS • The font-family property is used to change the face of a font. • The font-style property is used to make a font italic or oblique. • The font-variant property is used to create a small-caps effect. • The font-weight property is used to increase or decrease how bold or light a font appears. • The font-size property is used to increase or decrease the size of a font. • The font property is used as shorthand to specify a number of other font properties.
  • 26. <p style="font-family:georgia,garamond,serif;"> This text is rendered in either georgia, garamond, or the default serif font depending on which font you have at your system. </p> <p style="font-style:italic;"> This text will be rendered in italic style </p> <p style="font-variant:small-caps;"> This text will be rendered as small caps </p> <p style="font-weight:bold;"> This font is bold. </p>
  • 27. <p style="font-weight:bolder;"> This font is bolder. </p> <p style="font-weight:900;"> This font is 900 weight. </p> <p style="font-size:20px;"> This font size is 20 pixels </p> <p style="font-size:small;"> This font size is small </p> <p style="font-size:large;"> This font size is large </p> <p style="font:italic small-caps bold 15px greorgia;"> Applying all the properties on the text at once. </p>