SlideShare a Scribd company logo
Introduction to CSS
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.
• Advantages of CSS
• CSS saves time
When most of us first learn HTML, we get taught to set the font face, size,
colour, style etc every time it occurs on a page. This means we find
ourselves typing (or copying & pasting) the same thing over and over again.
With CSS, you only have to specify these details once for any element. CSS
will automatically apply the specified styles whenever that element occurs.
• Pages load faster
Less code means faster download times.
• Easy maintenance
To change the style of an element, you only have to make an edit in one
place.
• Superior styles to HTML
CSS has a much wider array of attributes than HTML.
• Disadvantages of CSS
• Browser compatibility
Browsers have varying levels of compliance with Style Sheets. This means
that some Style Sheet features are supported and some aren't. To confuse
things more, some browser manufacturers decide to come up with their own
proprietary tags.
7
How to write CSS?
• Selector
– HTML element tags
(examples: p, h2, body, img, table)
– class and ID names
• Property (examples: color, font-size)
• Value (examples: red, 14pt)
8
How to write CSS:
• The basic syntax of a CSS rule:
selector {property 1: value 1; property 2:
value 2}
Example:
p {font-size: 8pt; color: red}
Notice the { } around the rule and the : before
each value!
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;
}
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
CSS Units & Colors
• Units
– %
– in
– cm
– mm
– em (12pt)
– px
– pt
• Colors
– color name (red, etc)
– rgb(x,x,x)
– #rrggbb (HEX)
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.
The Box Model
• Every element in the DOM (Document Object Model) has a
conceptual “box” for presentation.
• The box consists of margin, padding, border, content
(width, height), and offset (top, left)
22
Properties - Font
• font-family
– Name, or serif, sans-serif, cursive, monospace
• font-style
– normal, italic
• font-weight
– normal, bold, 100, 200, 300, 400, 500, 600, 700, 800,
900
• font-size
– absolute-size, relative-size, length, percentage
• font-variant
– small-caps
23
Properties - Text
• text-decoration
– underline, line-through
• text-transform
– capitalize, uppercase, lowercase, none
• text-align
– left, right, center, justify
• text-indent
– <length>, <percentage>
24
Properties - Position
• position
– absolute, relative
• top
– <length>, <percentage>, auto
• left
– <length>, <percentage>, auto
• Z-index
– <number>, auto
CSS Layout
• Margin
• Padding
• Border
• Z-index
• Positioning
• Width
• Height
• Float
• Text-align
• Vertical-align
26
Backgrounds
• background-color
– Hex
• background-image
– URL(image.jpg)
• background-repeat
– No-repeat, repeat-x, repeat-y
• background-attachment
– Fixed, scroll
• background-position
– Top, left
• p { background-position: 70px 10px; background-repeat: repeat-y;
background-image: url(background.gif) }
Example
27
Background repeat examples:
CSS Lists
• List-style
• List-style-image
• List-style-position
• List-style-type
29
CSS Link
• a:link {color: #FFFFFF; text-decoration: none}
• a:visited {color: #808080; text-decoration: none}
• a:hover {color: red; text-decoration: none}
• a:active {color: blue; text-decoration: none}
CSS Shorthand
• Consolidates many styles into a single declaration.
font-family: verdana, sans-serif;
font-weight: bold;
font-size: 12px;
 font: bold 12px verdana, sans-serif;
padding-top: 5px;
padding-right: 8px;
padding-bottom: 5px;
padding-left: 10px;
 padding: 5px 8px 5px 10px;
31
Border values
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-elements/class { property: value
}
:link
:visited Link (A tag) related pseudo classes
:hover
:active
:first-child
::after
::before
::first-letter
::first-line
::selection
Pseudo Elements
Selector Example Example description
::after p::after Insert something after the content of each <p> element
::before p::before Insert something before the content of each <p> element
::first-letter p::first-letter Selects the first letter of each <p> element
::first-line p::first-line Selects the first line of each <p> element
::selection p::selection Selects the portion of an element that is selected by a
user
2 introduction css
2 introduction css
Refrences
• www.w3schools.com
• www.w3.org
• World wide web

More Related Content

PDF
4. Web Technology CSS Basics-1
PPTX
Howcssworks 100207024009-phpapp01
PPTX
Cascading style sheets - CSS
PPT
Cascading Style Sheets(CSS)
PPT
CSS Introduction
PPTX
css v1 guru
PPTX
PPT
Cascading Style Sheets (CSS) help
4. Web Technology CSS Basics-1
Howcssworks 100207024009-phpapp01
Cascading style sheets - CSS
Cascading Style Sheets(CSS)
CSS Introduction
css v1 guru
Cascading Style Sheets (CSS) help

What's hot (20)

PPT
Introduction to CSS
PPTX
1 03 - CSS Introduction
PPTX
PPSX
Introduction to css
PPTX
CSS introduction
PPTX
Beginners css tutorial for web designers
PPTX
Cascading style sheets
PDF
Intro to css & sass
PDF
Html css
PPTX
PPTX
Responsive web design with html5 and css3
PPT
Introduction to Cascading Style Sheets (CSS)
PDF
PPT
Basic css
PPT
CSS
PPTX
Cascading Style Sheet (CSS)
Introduction to CSS
1 03 - CSS Introduction
Introduction to css
CSS introduction
Beginners css tutorial for web designers
Cascading style sheets
Intro to css & sass
Html css
Responsive web design with html5 and css3
Introduction to Cascading Style Sheets (CSS)
Basic css
CSS
Cascading Style Sheet (CSS)
Ad

Similar to 2 introduction css (20)

PDF
Introduction to CSS3
PDF
CSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
PPTX
uptu web technology unit 2 Css
PPTX
HTML-CSS-QUARTER4 COMPUTER PROGRAMMING SSC
PPTX
Kick start @ css
PPTX
Cordova training - Day 2 Introduction to CSS 3
PPT
CSS Training in Bangalore
PPTX
CSS – CASCADING STYLE SHEET - MY_PPT.pptx
PPTX
css3.0.( Cascading Style Sheets ) pptx
PDF
Unit 3 (it workshop).pptx
PPTX
PDF
ch-hguygureehuvnvdfduyertiuhrnhduuyfjh3.pdf
PPTX
Module 2 CSS . cascading style sheet and its uses
PPTX
PPTX
v5-introduction to html-css-210321161444.pptx
PPT
CSS - Basics
PPTX
Web Engineering - Introduction to CSS
PPTX
UNIT 3WOP fgfufhbuiibpvihbvpihivbhibvipuuvbiuvboi
PPTX
PPTX
Css ppt
Introduction to CSS3
CSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
uptu web technology unit 2 Css
HTML-CSS-QUARTER4 COMPUTER PROGRAMMING SSC
Kick start @ css
Cordova training - Day 2 Introduction to CSS 3
CSS Training in Bangalore
CSS – CASCADING STYLE SHEET - MY_PPT.pptx
css3.0.( Cascading Style Sheets ) pptx
Unit 3 (it workshop).pptx
ch-hguygureehuvnvdfduyertiuhrnhduuyfjh3.pdf
Module 2 CSS . cascading style sheet and its uses
v5-introduction to html-css-210321161444.pptx
CSS - Basics
Web Engineering - Introduction to CSS
UNIT 3WOP fgfufhbuiibpvihbvpihivbhibvipuuvbiuvboi
Css ppt
Ad

More from Jalpesh Vasa (16)

PDF
Object Oriented PHP - PART-1
PDF
Object Oriented PHP - PART-2
PDF
5. HTML5
PDF
4.4 PHP Session
PDF
4.3 MySQL + PHP
PDF
4.2 PHP Function
PDF
4.1 PHP Arrays
PDF
4 Basic PHP
PDF
3.2.1 javascript regex example
PDF
3.2 javascript regex
PDF
3. Java Script
PDF
3.1 javascript objects_DOM
PDF
1 web technologies
PDF
Remote Method Invocation in JAVA
PDF
Kotlin for android development
PDF
Security in php
Object Oriented PHP - PART-1
Object Oriented PHP - PART-2
5. HTML5
4.4 PHP Session
4.3 MySQL + PHP
4.2 PHP Function
4.1 PHP Arrays
4 Basic PHP
3.2.1 javascript regex example
3.2 javascript regex
3. Java Script
3.1 javascript objects_DOM
1 web technologies
Remote Method Invocation in JAVA
Kotlin for android development
Security in php

Recently uploaded (20)

PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
English Language Teaching from Post-.pdf
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
How to Manage Bill Control Policy in Odoo 18
PDF
Insiders guide to clinical Medicine.pdf
PDF
Landforms and landscapes data surprise preview
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Open Quiz Monsoon Mind Game Prelims.pptx
Open folder Downloads.pdf yes yes ges yes
English Language Teaching from Post-.pdf
How to Manage Starshipit in Odoo 18 - Odoo Slides
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
How to Manage Loyalty Points in Odoo 18 Sales
How to Manage Bill Control Policy in Odoo 18
Insiders guide to clinical Medicine.pdf
Landforms and landscapes data surprise preview
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
human mycosis Human fungal infections are called human mycosis..pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Onica Farming 24rsclub profitable farm business
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx

2 introduction css

  • 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. • Advantages of CSS • CSS saves time When most of us first learn HTML, we get taught to set the font face, size, colour, style etc every time it occurs on a page. This means we find ourselves typing (or copying & pasting) the same thing over and over again. With CSS, you only have to specify these details once for any element. CSS will automatically apply the specified styles whenever that element occurs. • Pages load faster Less code means faster download times. • Easy maintenance To change the style of an element, you only have to make an edit in one place. • Superior styles to HTML CSS has a much wider array of attributes than HTML. • Disadvantages of CSS • Browser compatibility Browsers have varying levels of compliance with Style Sheets. This means that some Style Sheet features are supported and some aren't. To confuse things more, some browser manufacturers decide to come up with their own proprietary tags.
  • 7. 7 How to write CSS? • Selector – HTML element tags (examples: p, h2, body, img, table) – class and ID names • Property (examples: color, font-size) • Value (examples: red, 14pt)
  • 8. 8 How to write CSS: • The basic syntax of a CSS rule: selector {property 1: value 1; property 2: value 2} Example: p {font-size: 8pt; color: red} Notice the { } around the rule and the : before each value!
  • 9. 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" />
  • 10. 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.
  • 11. CSS Selectors • ID based ( #) HTML CSS <div id=“content”> #content { Text width: 200px; </div> } ID selectors should be used with single elements.
  • 12. 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.
  • 13. 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>
  • 14. Grouping • Multiple selectors can be grouped in a single style declaration by using , . H1, P , .main { font-weight:bold; }
  • 15. 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).
  • 16. Categories of CSS properties • Positioning and layout handling related. • Background related properties. • Font and text related • Links related. • Lists related. • Table related.
  • 17. 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)
  • 18. CSS Specificity Rule 1. CSS File >> Embedded >> Inline Rule 2. TAG >> class >> ID
  • 19. CSS Units & Colors • Units – % – in – cm – mm – em (12pt) – px – pt • Colors – color name (red, etc) – rgb(x,x,x) – #rrggbb (HEX)
  • 20. 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.
  • 21. The Box Model • Every element in the DOM (Document Object Model) has a conceptual “box” for presentation. • The box consists of margin, padding, border, content (width, height), and offset (top, left)
  • 22. 22 Properties - Font • font-family – Name, or serif, sans-serif, cursive, monospace • font-style – normal, italic • font-weight – normal, bold, 100, 200, 300, 400, 500, 600, 700, 800, 900 • font-size – absolute-size, relative-size, length, percentage • font-variant – small-caps
  • 23. 23 Properties - Text • text-decoration – underline, line-through • text-transform – capitalize, uppercase, lowercase, none • text-align – left, right, center, justify • text-indent – <length>, <percentage>
  • 24. 24 Properties - Position • position – absolute, relative • top – <length>, <percentage>, auto • left – <length>, <percentage>, auto • Z-index – <number>, auto
  • 25. CSS Layout • Margin • Padding • Border • Z-index • Positioning • Width • Height • Float • Text-align • Vertical-align
  • 26. 26 Backgrounds • background-color – Hex • background-image – URL(image.jpg) • background-repeat – No-repeat, repeat-x, repeat-y • background-attachment – Fixed, scroll • background-position – Top, left • p { background-position: 70px 10px; background-repeat: repeat-y; background-image: url(background.gif) } Example
  • 28. CSS Lists • List-style • List-style-image • List-style-position • List-style-type
  • 29. 29 CSS Link • a:link {color: #FFFFFF; text-decoration: none} • a:visited {color: #808080; text-decoration: none} • a:hover {color: red; text-decoration: none} • a:active {color: blue; text-decoration: none}
  • 30. CSS Shorthand • Consolidates many styles into a single declaration. font-family: verdana, sans-serif; font-weight: bold; font-size: 12px;  font: bold 12px verdana, sans-serif; padding-top: 5px; padding-right: 8px; padding-bottom: 5px; padding-left: 10px;  padding: 5px 8px 5px 10px;
  • 32. 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>
  • 33. 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>
  • 34. Universal selectors Universal selectors are used to select any element. * { color: blue; }
  • 35. 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>
  • 36. 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” />
  • 37. CSS Pseudo-classes selector:pseudo-elements/class { property: value } :link :visited Link (A tag) related pseudo classes :hover :active :first-child ::after ::before ::first-letter ::first-line ::selection
  • 38. Pseudo Elements Selector Example Example description ::after p::after Insert something after the content of each <p> element ::before p::before Insert something before the content of each <p> element ::first-letter p::first-letter Selects the first letter of each <p> element ::first-line p::first-line Selects the first line of each <p> element ::selection p::selection Selects the portion of an element that is selected by a user