SlideShare ist ein Scribd-Unternehmen logo
1 von 58
WEB TECHNOLOGY
Cascading Stylesheets
Dr. KOYEL DATTA GUPTA
CSS Introduction
◌ Cascading Style Sheets (CSS)
â–Ș Used to describe the presentation of documents
â–Ș Define sizes, spacing, fonts, colors, layout, etc.
â–Ș Improve content accessibility
â–Ș Improve flexibility
◌ Designed to separate presentation from content
◌ Due to CSS, all HTML presentation tags and
attributes are deprecated, e.g. font, center,
etc.
2
CSS Introduction
â—ŒCSS can be applied to any XML document
â–Ș Not just to HTML / XHTML
â—ŒCSS can specify different styles for different
media
3
Why “Cascading”?
â—ŒPriority scheme determining which style rules
apply to element
â–Ș Cascade priorities or specificity (weight) are
calculated and assigned to the rules
â–Ș Child elements in the HTML DOM tree inherit
styles from their parent
â–Ș Can override them
4
Why “Cascading”?
5
Why “Cascading”?
â—ŒSome CSS styles are inherited and some not
â–Ș Text-related and list-related properties are
inherited - color, font-size, font-family,
line-height, text-align, list-style, etc
â–Ș Box-related and positioning styles are not
inherited - width, height, border, margin,
padding, position, float, etc
â–Ș <a> elements do not inherit color and text-
decoration
6
Style Sheets Syntax
◌ Stylesheets consist of rules, selectors,
declarations, properties and values
◌ Selectors are separated by commas
◌ Declarations are separated by semicolons
◌ Properties and values are separated by colons
7
h1,h2,h3 { color: green; font-weight: bold; }
Selectors
â—ŒSelectors determine which element the rule
applies to:
â–Ș All elements of specific type (tag)
â–Ș Those that match a specific attribute (id, class)
â–Ș Elements may be matched depending on how
they are nested in the document tree (HTML)
8
Selectors
◌ Three primary kinds of selectors:
â–Ș By tag (type selector):
â–Ș By element id:
â–Ș By element class name (only for HTML):
◌ Selectors can be combined with commas:
This will match <h1> tags, elements with class link, 9
h1 { font-family: verdana,sans-serif; }
#element_id { color: #ff0000; }
.myClass {border: 1px solid red}
h1, .link, #top-link {font-weight: bold}
Selectors
â—ŒPseudo-classes define state
â–Ș :hover, :visited, :active , :lang
â—ŒPseudo-elements define element "parts" or
are used to generate content
â–Ș :first-line , :before, :after
10
a:hover { color: red; }
p:first-line { text-transform: uppercase; }
.title:before { content: "»"; }
.title:after { content: "«"; }
Selectors
◌ Match relative to element placement:
This will match all <a> tags that are inside of <p>
â—Œ * – universal selector (avoid or use with care!):
This will match all descendants of <p> element
â—Œ + selector – used to match “next sibling”:
This will match all siblings with class name link
that appear immediately after <img> tag
11
p a {text-decoration: underline}
p * {color: black}
img + .link {float:right}
Selectors
â—Œ > selector – matches direct child nodes:
This will match all elements with class error, direct
children of <p> tag
â—Œ [ ] – matches tag attributes by regular expression:
This will match all <img> tags with alt attribute
containing the word logo
◌ .class1.class2 (no space) - matches elements
with both (all) classes applied at the same time
12
p > .error {font-size: 8px}
img[alt~=logo] {border: none}
Values in the CSS Rules
◌ Colors are set in RGB format (decimal or hex):
â–Ș Example: #a0a6aa = rgb(160, 166, 170)
â–Ș Predefined color aliases exist: black, blue, etc.
◌ Numeric values are specified in:
â–Ș Pixels, ems, e.g. 12px , 1.4em
â–Ș Points, inches, centimeters, millimeters
â–Ș E.g. 10pt , 1in, 1cm, 1mm
â–Ș Percentages, e.g. 50%
â–Ș Percentage of what?...
â–Ș Zero can be used with no unit: border: 0;
13
Default Browser Styles
â—ŒBrowsers have default CSS styles
â–Ș Used when there is no CSS information or any
other style information in the document
â—ŒCaution: default styles differ in browsers
â–Ș E.g. margins, paddings and font sizes differ most
often and usually developers reset them
14
* { margin: 0; padding: 0; }
body, h1, p, ul, li { margin: 0; padding: 0; }
Linking HTML and CSS
â—ŒHTML (content) and CSS (presentation) can be
linked in three ways:
â–Ș Inline: the CSS rules in the style attribute
â–Ș No selectors are needed
â–Ș Embedded: in the <head> in a <style> tag
â–Ș External: CSS rules in separate file (best)
â–Ș Usually a file with .css extension
â–Ș Linked via <link rel="stylesheet" href=
> tag or
@import directive in embedded CSS block
15
Linking HTML and CSS (2)
â—ŒUsing external files is highly recommended
â–Ș Simplifies the HTML document
â–Ș Improves page load speed as the CSS file is
cached
16
Inline Styles: Example
17
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/
DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inline Styles</title>
</head>
<body>
<p>Here is some text</p>
<!--Separate multiple styles with a semicolon-->
<p style="font-size: 20pt">Here is some
more text</p>
<p style="font-size: 20pt;color:
#0000FF" >Even more text</p>
</body>
</html>
inline-styles.html
Inline Styles: Example
18
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/ DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inline Styles</title>
</head>
<body>
<p>Here is some text</p>
<!--Separate multiple styles with a
semicolon-->
<p style="font-size: 20pt">Here is some
more text</p>
<p style="font-size: 20pt;color:
#0000FF" >Even more text</p>
</body>
</html>
inline-styles.html
CSS Cascade (Precedence)
â—ŒThere are browser, user and author
stylesheets with "normal" and "important"
declarations
â–Ș Browser styles (least priority)
â–Ș Normal user styles
â–Ș Normal author styles (external, in head, inline)
â–Ș Important author styles
â–Ș Important user styles (max priority)
19
a { color: red !important ; }
CSS Specificity
â—ŒCSS specificity is used to determine the
precedence of CSS style declarations with the
same origin. Selectors are what matters
â–Ș Simple calculation: #id = 100, .class = 10, :pseudo
= 10, [attr] = 10, tag = 1, * = 0
20
Embedded Styles
â—ŒEmbedded in the HTML in the <style> tag:
â–Ș The <style> tag is placed in the <head> section of
the document
â–Ș type attribute specifies the MIME type
â–Ș MIME describes the format of the content
â–Ș Other MIME types include text/html, image/gif,
text/javascript 

â—ŒUsed for document-specific styles
21
<style type="text/css">
Embedded Styles: Example
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Style Sheets</title>
<style type="text/css">
em {background-color:#8000FF; color:white}
h1 {font-family:Arial}
p {font-size:18pt}
.blue {color:blue}
</style>
<head>
embedded-stylesheets.html
Embedded Styles: Example (2)
23


<body>
<h1 class="blue">A Heading</h1>
<p>Here is some text. Here is some text. Here
is some text. Here is some text. Here is some
text.</p>
<h1>Another Heading</h1>
<p class="blue">Here is some more text.
Here is some more text.</p>
<p class="blue">Here is some <em>more</em>
text. Here is some more text.</p>
</body>
</html>


<body>
<h1 class="blue">A Heading</h1>
<p>Here is some text. Here is some
text. Here
is some text. Here is some text.
Here is some
text.</p>
<h1>Another Heading</h1>
<p class="blue">Here is some more
text.
Here is some more text.</p>
<p class="blue">Here is some
<em>more</em>
text. Here is some more text.</p>
</body>
</html>
Embedded Styles: Example (3)
24
External CSS Styles
◌ External linking
â–Ș Separate pages can all use a shared style sheet
â–Ș Only modify a single file to change the styles across
your entire Web site
◌ link tag (with a rel attribute)
â–Ș Specifies a relationship between current document
and another document
â–Ș link elements should be in the <head>
25
<link rel="stylesheet" type="text/css"
href="styles.css">
External CSS Styles (2)
@import
â–Ș Another way to link external CSS files
â–Ș Example:
â–Ș Ancient browsers do not recognize @import
â–Ș Use @import in an external CSS file to workaround
the IE 32 CSS file limit
26
<style type="text/css">
@import url("styles.css");
/* same as */
@import "styles.css";
</style>
External Styles: Example
27
/* CSS Document */
a { text-decoration: none }
a:hover { text-decoration: underline;
color: red;
background-color: #CCFFCC }
li em { color: red;
font-weight: bold }
ul { margin-left: 2cm }
ul ul { text-decoration: underline;
margin-left: .5cm }
styles.css
External Styles: Example (2)
28
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Importing style sheets</title>
<link type="text/css" rel="stylesheet"
href="styles.css" />
</head>
<body>
<h1>Shopping list for <em>Monday</em>:</h1>
<li>Milk</li>


external-styles.html
External Styles: Example (3)
29


<li>Bread
<ul>
<li>White bread</li>
<li>Rye bread</li>
<li>Whole wheat bread</li>
</ul>
</li>
<li>Rice</li>
<li>Potatoes</li>
<li>Pizza <em>with mushrooms</em></li>
</ul>
<a href="http://food.com" title="grocery
store">Go to the Grocery store</a>
</body>
</html>


<li>Bread
<ul>
<li>White bread</li>
<li>Rye bread</li>
<li>Whole wheat bread</li>
</ul>
</li>
<li>Rice</li>
<li>Potatoes</li>
<li>Pizza <em>with mushrooms</em></li>
</ul>
<a href="http://food.com" title="grocery
store">Go to the Grocery store</a>
</body>
</html>
External Styles: Example (4)
30
Text-related CSS Properties
â—Œ color – specifies the color of the text
â—Œ font-size – size of font: xx-small, x-small,
small, medium, large, x-large, xx-large,
smaller, larger or numeric value
â—Œ font-family – comma separated font names
â–Ș Example: verdana, sans-serif, etc.
â–Ș The browser loads the first one that is available
â–Ș There should always be at least one generic font
◌ font-weight can be normal, bold, bolder,
lighter or a number in range [100 
 900]
31
CSS Rules for Fonts (2)
â—Œfont-style – styles the font
â–Ș Values: normal, italic, oblique
â—Œtext-decoration – decorates the text
â–Ș Values: none, underline, line-trough,
overline, blink
â—Œtext-align – defines the alignment of text
or other content
â–Ș Values: left, right, center, justify
32
Shorthand Font Property
â—Œfont
â–Ș Shorthand rule for setting multiple font properties
at the same time
is equal to writing this:
33
font:italic normal bold 12px/16px verdana
font-style: italic;
font-variant: normal;
font-weight: bold;
font-size: 12px;
line-height: 16px;
font-family: verdana;
Backgrounds
â—Œbackground-image
â–Ș URL of image to be used as background, e.g.:
â—Œbackground-color
â–Ș Using color and image and the same time
â—Œbackground-repeat
â–Ș repeat-x, repeat-y, repeat, no-repeat
â—Œbackground-attachment
â–Ș fixed / scroll
34
background-image:url("back.gif");
Backgrounds (2)
â—Œbackground-position: specifies vertical
and horizontal position of the background
image
â–Ș Vertical position: top, center, bottom
â–Ș Horizontal position: left, center, right
â–Ș Both can be specified in percentage or other
numerical values
â–Ș Examples:
35
background-position: top left;
background-position: -5px 50%;
Background Shorthand Property
◌ background: shorthand rule for setting
background properties at the same time:
is equal to writing:
â–Ș Some browsers will not apply BOTH color and image
for background if using shorthand rule
36
background: #FFF0C0 url("back.gif") no-repeat
fixed top;
background-color: #FFF0C0;
background-image: url("back.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top;
Background-image or <img>?
â—ŒBackground images allow you to save many
image tags from the HTML
â–Ș Leads to less code
â–Ș More content-oriented approach
â—ŒAll images that are not part of the page
content (and are used only for
"beautification") should be moved to the CSS
37
Borders
â—Œborder-width: thin, medium, thick or
numerical value (e.g. 10px)
â—Œborder-color: color alias or RGB value
â—Œborder-style: none, hidden, dotted,
dashed, solid, double, groove, ridge,
inset, outset
â—ŒEach property can be defined separately for
left, top, bottom and right
â–Ș border-top-style, border-left-color, 

38
Border Shorthand Property
â—Œborder: shorthand rule for setting border
properties at once:
is equal to writing:
â—ŒSpecify different borders for the sides via
shorthand rules: border-top, border-
left, border-right, border-bottom
â—ŒWhen to avoid border:0
39
border: 1px solid red
border-width:1px;
border-color:red;
border-style:solid;
Width and Height
â—Œwidth – defines numerical value for the
width of element, e.g. 200px
â—Œheight – defines numerical value for the
height of element, e.g. 100px
â–Ș By default the height of an element is defined by
its content
â–Ș Inline elements do not apply height, unless you
change their display style.
40
Margin and Padding
â—Œmargin and padding define the spacing
around the element
â–Ș Numerical value, e.g. 10px or -5px
â–Ș Can be defined for each of the four sides
separately - margin-top, padding-left, 

â–Ș margin is the spacing outside of the border
â–Ș padding is the spacing between the border and
the content
â–Ș What are collapsing margins?
41
Margin and Padding: Short Rules
â—Œmargin: 5px;
â–Ș Sets all four sides to have margin of 5 px;
â—Œmargin: 10px 20px;
â–Ș top and bottom to 10px, left and right to 20px;
â—Œmargin: 5px 3px 8px;
â–Ș top 5px, left/right 3px, bottom 8px
â—Œmargin: 1px 3px 5px 7px;
â–Ș top, right, bottom, left (clockwise from top)
â—ŒSame for padding
42
The Box Model
43
IE Quirks Mode
◌ When using quirks
mode (pages with no
DOCTYPE or with a
HTML 4 Transitional
DOCTYPE), Internet
Explorer violates the
box model standard
44
Positioning
â—Œposition: defines the positioning of the
element in the page content flow
◌ The value is one of:
â–Ș static (default)
â–Ș relative – relative position according to where
the element would appear with static position
â–Ș absolute – position according to the innermost
positioned parent element
â–Ș fixed – same as absolute, but ignores page
scrolling
45
Positioning (2)
â—ŒMargin VS relative positioning
â—ŒFixed and absolutely positioned elements do
not influence the page normal flow and
usually stay on top of other elements
â–Ș Their position and size is ignored when calculating
the size of parent element or position of
surrounding elements
â–Ș Overlaid according to their z-index
â–Ș Inline fixed or absolutely positioned elements can
apply height like block-level elements
46
Positioning (3)
â—Œtop, left, bottom, right: specifies offset
of absolute/fixed/relative positioned element
as numerical values
â—Œz-index : specifies the stack level of
positioned elements
â–Ș Understanding stacking context
47
Each positioned element creates a stacking
context.
Elements in different stacking contexts are
overlapped according to the stacking order of
their containers. For example, there is no way
for #A1 and #A2 (children of #A) to be placed
over #B without increasing the z-index of #A.
Inline element positioning
â—Œvertical-align: sets the vertical-
alignment of an inline element, according to
the line height
â–Ș Values: baseline, sub, super, top, text-top,
middle, bottom, text-bottom or numeric
◆Also used for content of table cells (which apply
middle alignment by default)
48
Float
â—Œfloat: the element “floats” to one side
â–Ș left: places the element on the left and
following content on the right
â–Ș right: places the element on the right and
following content on the left
â–Ș floated elements should come before the content
that will wrap around them in the code
â–Ș margins of floated elements do not collapse
â–Ș floated inline elements can apply height
49
Float (2)
â—ŒHow floated elements are positioned
50
Clear
â—Œclear
â–Ș Sets the sides of the element where other floating
elements are NOT allowed
â–Ș Used to "drop" elements below floated ones or
expand a container, which contains only floated
children
â–Ș Possible values: left, right, both
◌ Clearing floats
â–Ș additional element (<div>) with a clear style
51
Clear (2)
◌ Clearing floats (continued)
â–Ș :after { content: ""; display: block;
clear: both; height: 0; }
â–Ș Triggering hasLayout in IE expands a container of
floated elements
â–Ș display: inline-block;
â–Ș zoom: 1;
52
Opacity
â—Œopacity: specifies the opacity of the
element
â–Ș Floating point number from 0 to 1
â–Ș For old Mozilla browsers use –moz-opacity
â–Ș For IE use filter:alpha(opacity=value)
where value is from 0 to 100; also, "binary and
script behaviors" must be enabled and
hasLayout must be triggered, e.g. with zoom:1
53
Visibility
â—Œvisibility
â–Ș Determines whether the element is visible
â–Ș hidden: element is not rendered, but still
occupies place on the page (similar to
opacity:0)
â–Ș visible: element is rendered normally
54
Display
â—Œdisplay: controls the display of the element
and the way it is rendered and if breaks
should be placed before and after the
element
â–Ș inline: no breaks are placed before and after
(<span> is an inline element)
â–Ș block: breaks are placed before AND after the
element (<div> is a block element)
55
Display (2)
â—Œdisplay: controls the display of the element
and the way it is rendered and if breaks
should be placed before and after the
element
â–Ș none: element is hidden and its dimensions are
not used to calculate the surrounding elements
rendering (differs from visibility: hidden!)
â–Ș There are some more possible values, but not all
browsers support them
â–Ș Specific displays like table-cell and table-row
56
Overflow
◌ overflow: defines the behavior of element when
content needs more space than you have specified by
the size properties or for other reasons. Values:
â–Ș visible (default) – content spills out of the element
â–Ș auto - show scrollbars if needed
â–Ș scroll – always show scrollbars
â–Ș hidden – any content that cannot fit is clipped
57
Other CSS Properties
â—Œcursor: specifies the look of the mouse
cursor when placed over the element
â–Ș Values: crosshair, help, pointer, progress,
move, hair, col-resize, row-resize, text,
wait, copy, drop, and others
â—Œwhite-space – controls the line breaking of
text. Value is one of:
â–Ș nowrap – keeps the text on one line
â–Ș normal (default) – browser decides whether to
brake the lines if needed
58

Weitere Àhnliche Inhalte

Was ist angesagt?

Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Chris Poteet
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notesSanthiya Grace
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheetMichael Jhon
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorialtutorialsruby
 
Introducing Cascading Style Sheets
Introducing Cascading Style SheetsIntroducing Cascading Style Sheets
Introducing Cascading Style SheetsSt. Petersburg College
 
Cascading style sheets (CSS)
Cascading style sheets (CSS)Cascading style sheets (CSS)
Cascading style sheets (CSS)Harshita Yadav
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxpriyadharshini murugan
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpcasestudyhelp
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSAmit Tyagi
 
Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)Harshil Darji
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style SheetsMarc Steel
 

Was ist angesagt? (20)

Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
 
Week 12 CSS - Review from last week
Week 12 CSS - Review from last weekWeek 12 CSS - Review from last week
Week 12 CSS - Review from last week
 
Css
CssCss
Css
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
Introducing Cascading Style Sheets
Introducing Cascading Style SheetsIntroducing Cascading Style Sheets
Introducing Cascading Style Sheets
 
Basic css
Basic cssBasic css
Basic css
 
Cascading style sheets (CSS)
Cascading style sheets (CSS)Cascading style sheets (CSS)
Cascading style sheets (CSS)
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
 
What is CSS?
What is CSS?What is CSS?
What is CSS?
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 

Ähnlich wie Cascading Style Sheet

ch04-css-basics_final.ppt
ch04-css-basics_final.pptch04-css-basics_final.ppt
ch04-css-basics_final.pptGmachImen
 
2 introduction css
2 introduction css2 introduction css
2 introduction cssJalpesh Vasa
 
Unit 3 (it workshop).pptx
Unit 3 (it workshop).pptxUnit 3 (it workshop).pptx
Unit 3 (it workshop).pptxDr.Lokesh Gagnani
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssTesfaye Yenealem
 
Css ms megha
Css ms meghaCss ms megha
Css ms meghaMegha Gupta
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to cssJoseph Gabriel
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheetssmithaps4
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsQA TrainingHub
 
Css introduction
Css  introductionCss  introduction
Css introductionvishnu murthy
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheetssmitha273566
 
Css introduction
Css introductionCss introduction
Css introductionSridhar P
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSSSun Technlogies
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1Jyoti Yadav
 

Ähnlich wie Cascading Style Sheet (20)

CSS Overview
CSS OverviewCSS Overview
CSS Overview
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
ch04-css-basics_final.ppt
ch04-css-basics_final.pptch04-css-basics_final.ppt
ch04-css-basics_final.ppt
 
Cascstylesheets
CascstylesheetsCascstylesheets
Cascstylesheets
 
2 introduction css
2 introduction css2 introduction css
2 introduction css
 
CSS Part I
CSS Part ICSS Part I
CSS Part I
 
Unit 3 (it workshop).pptx
Unit 3 (it workshop).pptxUnit 3 (it workshop).pptx
Unit 3 (it workshop).pptx
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
Css ms megha
Css ms meghaCss ms megha
Css ms megha
 
CSS-part-1.ppt
CSS-part-1.pptCSS-part-1.ppt
CSS-part-1.ppt
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Css introduction
Css introductionCss introduction
Css introduction
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
CSS
CSSCSS
CSS
 
Css
CssCss
Css
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
 

Mehr von KushagraChadha1

Servlet and concurrency
Servlet and concurrencyServlet and concurrency
Servlet and concurrencyKushagraChadha1
 
Compiler Design IPU notes Handwritten
Compiler Design IPU notes HandwrittenCompiler Design IPU notes Handwritten
Compiler Design IPU notes HandwrittenKushagraChadha1
 
Web Engineering Notes Handwritten
Web Engineering Notes HandwrittenWeb Engineering Notes Handwritten
Web Engineering Notes HandwrittenKushagraChadha1
 
Optical Character Reader - Project Report BTech
Optical Character Reader - Project Report BTechOptical Character Reader - Project Report BTech
Optical Character Reader - Project Report BTechKushagraChadha1
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileKushagraChadha1
 
Communication Skills for Professionals
Communication Skills for ProfessionalsCommunication Skills for Professionals
Communication Skills for ProfessionalsKushagraChadha1
 
Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case StudyKushagraChadha1
 

Mehr von KushagraChadha1 (8)

Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet and concurrency
Servlet and concurrencyServlet and concurrency
Servlet and concurrency
 
Compiler Design IPU notes Handwritten
Compiler Design IPU notes HandwrittenCompiler Design IPU notes Handwritten
Compiler Design IPU notes Handwritten
 
Web Engineering Notes Handwritten
Web Engineering Notes HandwrittenWeb Engineering Notes Handwritten
Web Engineering Notes Handwritten
 
Optical Character Reader - Project Report BTech
Optical Character Reader - Project Report BTechOptical Character Reader - Project Report BTech
Optical Character Reader - Project Report BTech
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical File
 
Communication Skills for Professionals
Communication Skills for ProfessionalsCommunication Skills for Professionals
Communication Skills for Professionals
 
Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case Study
 

KĂŒrzlich hochgeladen

WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...Delhi Call girls
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Lucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRL
Lucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRLLucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRL
Lucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRLimonikaupta
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...SofiyaSharma5
 
✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
CALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service Onlineanilsa9823
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 

KĂŒrzlich hochgeladen (20)

WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎ 9205541914 ☎ Independent Esc...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
Lucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRL
Lucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRLLucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRL
Lucknow ❀CALL GIRL 88759*99948 ❀CALL GIRLS IN Lucknow ESCORT SERVICE❀CALL GIRL
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔☆9289244007✔☆ Female E...
 
✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
CALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➄8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
â‚č5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 

Cascading Style Sheet

  • 2. CSS Introduction â—Œ Cascading Style Sheets (CSS) â–Ș Used to describe the presentation of documents â–Ș Define sizes, spacing, fonts, colors, layout, etc. â–Ș Improve content accessibility â–Ș Improve flexibility â—Œ Designed to separate presentation from content â—Œ Due to CSS, all HTML presentation tags and attributes are deprecated, e.g. font, center, etc. 2
  • 3. CSS Introduction â—ŒCSS can be applied to any XML document â–Ș Not just to HTML / XHTML â—ŒCSS can specify different styles for different media 3
  • 4. Why “Cascading”? â—ŒPriority scheme determining which style rules apply to element â–Ș Cascade priorities or specificity (weight) are calculated and assigned to the rules â–Ș Child elements in the HTML DOM tree inherit styles from their parent â–Ș Can override them 4
  • 6. Why “Cascading”? â—ŒSome CSS styles are inherited and some not â–Ș Text-related and list-related properties are inherited - color, font-size, font-family, line-height, text-align, list-style, etc â–Ș Box-related and positioning styles are not inherited - width, height, border, margin, padding, position, float, etc â–Ș <a> elements do not inherit color and text- decoration 6
  • 7. Style Sheets Syntax â—Œ Stylesheets consist of rules, selectors, declarations, properties and values â—Œ Selectors are separated by commas â—Œ Declarations are separated by semicolons â—Œ Properties and values are separated by colons 7 h1,h2,h3 { color: green; font-weight: bold; }
  • 8. Selectors â—ŒSelectors determine which element the rule applies to: â–Ș All elements of specific type (tag) â–Ș Those that match a specific attribute (id, class) â–Ș Elements may be matched depending on how they are nested in the document tree (HTML) 8
  • 9. Selectors â—Œ Three primary kinds of selectors: â–Ș By tag (type selector): â–Ș By element id: â–Ș By element class name (only for HTML): â—Œ Selectors can be combined with commas: This will match <h1> tags, elements with class link, 9 h1 { font-family: verdana,sans-serif; } #element_id { color: #ff0000; } .myClass {border: 1px solid red} h1, .link, #top-link {font-weight: bold}
  • 10. Selectors â—ŒPseudo-classes define state â–Ș :hover, :visited, :active , :lang â—ŒPseudo-elements define element "parts" or are used to generate content â–Ș :first-line , :before, :after 10 a:hover { color: red; } p:first-line { text-transform: uppercase; } .title:before { content: "»"; } .title:after { content: "«"; }
  • 11. Selectors â—Œ Match relative to element placement: This will match all <a> tags that are inside of <p> â—Œ * – universal selector (avoid or use with care!): This will match all descendants of <p> element â—Œ + selector – used to match “next sibling”: This will match all siblings with class name link that appear immediately after <img> tag 11 p a {text-decoration: underline} p * {color: black} img + .link {float:right}
  • 12. Selectors â—Œ > selector – matches direct child nodes: This will match all elements with class error, direct children of <p> tag â—Œ [ ] – matches tag attributes by regular expression: This will match all <img> tags with alt attribute containing the word logo â—Œ .class1.class2 (no space) - matches elements with both (all) classes applied at the same time 12 p > .error {font-size: 8px} img[alt~=logo] {border: none}
  • 13. Values in the CSS Rules â—Œ Colors are set in RGB format (decimal or hex): â–Ș Example: #a0a6aa = rgb(160, 166, 170) â–Ș Predefined color aliases exist: black, blue, etc. â—Œ Numeric values are specified in: â–Ș Pixels, ems, e.g. 12px , 1.4em â–Ș Points, inches, centimeters, millimeters â–Ș E.g. 10pt , 1in, 1cm, 1mm â–Ș Percentages, e.g. 50% â–Ș Percentage of what?... â–Ș Zero can be used with no unit: border: 0; 13
  • 14. Default Browser Styles â—ŒBrowsers have default CSS styles â–Ș Used when there is no CSS information or any other style information in the document â—ŒCaution: default styles differ in browsers â–Ș E.g. margins, paddings and font sizes differ most often and usually developers reset them 14 * { margin: 0; padding: 0; } body, h1, p, ul, li { margin: 0; padding: 0; }
  • 15. Linking HTML and CSS â—ŒHTML (content) and CSS (presentation) can be linked in three ways: â–Ș Inline: the CSS rules in the style attribute â–Ș No selectors are needed â–Ș Embedded: in the <head> in a <style> tag â–Ș External: CSS rules in separate file (best) â–Ș Usually a file with .css extension â–Ș Linked via <link rel="stylesheet" href=
> tag or @import directive in embedded CSS block 15
  • 16. Linking HTML and CSS (2) â—ŒUsing external files is highly recommended â–Ș Simplifies the HTML document â–Ș Improves page load speed as the CSS file is cached 16
  • 17. Inline Styles: Example 17 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Inline Styles</title> </head> <body> <p>Here is some text</p> <!--Separate multiple styles with a semicolon--> <p style="font-size: 20pt">Here is some more text</p> <p style="font-size: 20pt;color: #0000FF" >Even more text</p> </body> </html> inline-styles.html
  • 18. Inline Styles: Example 18 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Inline Styles</title> </head> <body> <p>Here is some text</p> <!--Separate multiple styles with a semicolon--> <p style="font-size: 20pt">Here is some more text</p> <p style="font-size: 20pt;color: #0000FF" >Even more text</p> </body> </html> inline-styles.html
  • 19. CSS Cascade (Precedence) â—ŒThere are browser, user and author stylesheets with "normal" and "important" declarations â–Ș Browser styles (least priority) â–Ș Normal user styles â–Ș Normal author styles (external, in head, inline) â–Ș Important author styles â–Ș Important user styles (max priority) 19 a { color: red !important ; }
  • 20. CSS Specificity â—ŒCSS specificity is used to determine the precedence of CSS style declarations with the same origin. Selectors are what matters â–Ș Simple calculation: #id = 100, .class = 10, :pseudo = 10, [attr] = 10, tag = 1, * = 0 20
  • 21. Embedded Styles â—ŒEmbedded in the HTML in the <style> tag: â–Ș The <style> tag is placed in the <head> section of the document â–Ș type attribute specifies the MIME type â–Ș MIME describes the format of the content â–Ș Other MIME types include text/html, image/gif, text/javascript 
 â—ŒUsed for document-specific styles 21 <style type="text/css">
  • 22. Embedded Styles: Example 22 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Style Sheets</title> <style type="text/css"> em {background-color:#8000FF; color:white} h1 {font-family:Arial} p {font-size:18pt} .blue {color:blue} </style> <head> embedded-stylesheets.html
  • 23. Embedded Styles: Example (2) 23 
 <body> <h1 class="blue">A Heading</h1> <p>Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.</p> <h1>Another Heading</h1> <p class="blue">Here is some more text. Here is some more text.</p> <p class="blue">Here is some <em>more</em> text. Here is some more text.</p> </body> </html>
  • 24. 
 <body> <h1 class="blue">A Heading</h1> <p>Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.</p> <h1>Another Heading</h1> <p class="blue">Here is some more text. Here is some more text.</p> <p class="blue">Here is some <em>more</em> text. Here is some more text.</p> </body> </html> Embedded Styles: Example (3) 24
  • 25. External CSS Styles â—Œ External linking â–Ș Separate pages can all use a shared style sheet â–Ș Only modify a single file to change the styles across your entire Web site â—Œ link tag (with a rel attribute) â–Ș Specifies a relationship between current document and another document â–Ș link elements should be in the <head> 25 <link rel="stylesheet" type="text/css" href="styles.css">
  • 26. External CSS Styles (2) @import â–Ș Another way to link external CSS files â–Ș Example: â–Ș Ancient browsers do not recognize @import â–Ș Use @import in an external CSS file to workaround the IE 32 CSS file limit 26 <style type="text/css"> @import url("styles.css"); /* same as */ @import "styles.css"; </style>
  • 27. External Styles: Example 27 /* CSS Document */ a { text-decoration: none } a:hover { text-decoration: underline; color: red; background-color: #CCFFCC } li em { color: red; font-weight: bold } ul { margin-left: 2cm } ul ul { text-decoration: underline; margin-left: .5cm } styles.css
  • 28. External Styles: Example (2) 28 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Importing style sheets</title> <link type="text/css" rel="stylesheet" href="styles.css" /> </head> <body> <h1>Shopping list for <em>Monday</em>:</h1> <li>Milk</li> 
 external-styles.html
  • 29. External Styles: Example (3) 29 
 <li>Bread <ul> <li>White bread</li> <li>Rye bread</li> <li>Whole wheat bread</li> </ul> </li> <li>Rice</li> <li>Potatoes</li> <li>Pizza <em>with mushrooms</em></li> </ul> <a href="http://food.com" title="grocery store">Go to the Grocery store</a> </body> </html>
  • 30. 
 <li>Bread <ul> <li>White bread</li> <li>Rye bread</li> <li>Whole wheat bread</li> </ul> </li> <li>Rice</li> <li>Potatoes</li> <li>Pizza <em>with mushrooms</em></li> </ul> <a href="http://food.com" title="grocery store">Go to the Grocery store</a> </body> </html> External Styles: Example (4) 30
  • 31. Text-related CSS Properties â—Œ color – specifies the color of the text â—Œ font-size – size of font: xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger or numeric value â—Œ font-family – comma separated font names â–Ș Example: verdana, sans-serif, etc. â–Ș The browser loads the first one that is available â–Ș There should always be at least one generic font â—Œ font-weight can be normal, bold, bolder, lighter or a number in range [100 
 900] 31
  • 32. CSS Rules for Fonts (2) â—Œfont-style – styles the font â–Ș Values: normal, italic, oblique â—Œtext-decoration – decorates the text â–Ș Values: none, underline, line-trough, overline, blink â—Œtext-align – defines the alignment of text or other content â–Ș Values: left, right, center, justify 32
  • 33. Shorthand Font Property â—Œfont â–Ș Shorthand rule for setting multiple font properties at the same time is equal to writing this: 33 font:italic normal bold 12px/16px verdana font-style: italic; font-variant: normal; font-weight: bold; font-size: 12px; line-height: 16px; font-family: verdana;
  • 34. Backgrounds â—Œbackground-image â–Ș URL of image to be used as background, e.g.: â—Œbackground-color â–Ș Using color and image and the same time â—Œbackground-repeat â–Ș repeat-x, repeat-y, repeat, no-repeat â—Œbackground-attachment â–Ș fixed / scroll 34 background-image:url("back.gif");
  • 35. Backgrounds (2) â—Œbackground-position: specifies vertical and horizontal position of the background image â–Ș Vertical position: top, center, bottom â–Ș Horizontal position: left, center, right â–Ș Both can be specified in percentage or other numerical values â–Ș Examples: 35 background-position: top left; background-position: -5px 50%;
  • 36. Background Shorthand Property â—Œ background: shorthand rule for setting background properties at the same time: is equal to writing: â–Ș Some browsers will not apply BOTH color and image for background if using shorthand rule 36 background: #FFF0C0 url("back.gif") no-repeat fixed top; background-color: #FFF0C0; background-image: url("back.gif"); background-repeat: no-repeat; background-attachment: fixed; background-position: top;
  • 37. Background-image or <img>? â—ŒBackground images allow you to save many image tags from the HTML â–Ș Leads to less code â–Ș More content-oriented approach â—ŒAll images that are not part of the page content (and are used only for "beautification") should be moved to the CSS 37
  • 38. Borders â—Œborder-width: thin, medium, thick or numerical value (e.g. 10px) â—Œborder-color: color alias or RGB value â—Œborder-style: none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset â—ŒEach property can be defined separately for left, top, bottom and right â–Ș border-top-style, border-left-color, 
 38
  • 39. Border Shorthand Property â—Œborder: shorthand rule for setting border properties at once: is equal to writing: â—ŒSpecify different borders for the sides via shorthand rules: border-top, border- left, border-right, border-bottom â—ŒWhen to avoid border:0 39 border: 1px solid red border-width:1px; border-color:red; border-style:solid;
  • 40. Width and Height â—Œwidth – defines numerical value for the width of element, e.g. 200px â—Œheight – defines numerical value for the height of element, e.g. 100px â–Ș By default the height of an element is defined by its content â–Ș Inline elements do not apply height, unless you change their display style. 40
  • 41. Margin and Padding â—Œmargin and padding define the spacing around the element â–Ș Numerical value, e.g. 10px or -5px â–Ș Can be defined for each of the four sides separately - margin-top, padding-left, 
 â–Ș margin is the spacing outside of the border â–Ș padding is the spacing between the border and the content â–Ș What are collapsing margins? 41
  • 42. Margin and Padding: Short Rules â—Œmargin: 5px; â–Ș Sets all four sides to have margin of 5 px; â—Œmargin: 10px 20px; â–Ș top and bottom to 10px, left and right to 20px; â—Œmargin: 5px 3px 8px; â–Ș top 5px, left/right 3px, bottom 8px â—Œmargin: 1px 3px 5px 7px; â–Ș top, right, bottom, left (clockwise from top) â—ŒSame for padding 42
  • 44. IE Quirks Mode â—Œ When using quirks mode (pages with no DOCTYPE or with a HTML 4 Transitional DOCTYPE), Internet Explorer violates the box model standard 44
  • 45. Positioning â—Œposition: defines the positioning of the element in the page content flow â—Œ The value is one of: â–Ș static (default) â–Ș relative – relative position according to where the element would appear with static position â–Ș absolute – position according to the innermost positioned parent element â–Ș fixed – same as absolute, but ignores page scrolling 45
  • 46. Positioning (2) â—ŒMargin VS relative positioning â—ŒFixed and absolutely positioned elements do not influence the page normal flow and usually stay on top of other elements â–Ș Their position and size is ignored when calculating the size of parent element or position of surrounding elements â–Ș Overlaid according to their z-index â–Ș Inline fixed or absolutely positioned elements can apply height like block-level elements 46
  • 47. Positioning (3) â—Œtop, left, bottom, right: specifies offset of absolute/fixed/relative positioned element as numerical values â—Œz-index : specifies the stack level of positioned elements â–Ș Understanding stacking context 47 Each positioned element creates a stacking context. Elements in different stacking contexts are overlapped according to the stacking order of their containers. For example, there is no way for #A1 and #A2 (children of #A) to be placed over #B without increasing the z-index of #A.
  • 48. Inline element positioning â—Œvertical-align: sets the vertical- alignment of an inline element, according to the line height â–Ș Values: baseline, sub, super, top, text-top, middle, bottom, text-bottom or numeric ◆Also used for content of table cells (which apply middle alignment by default) 48
  • 49. Float â—Œfloat: the element “floats” to one side â–Ș left: places the element on the left and following content on the right â–Ș right: places the element on the right and following content on the left â–Ș floated elements should come before the content that will wrap around them in the code â–Ș margins of floated elements do not collapse â–Ș floated inline elements can apply height 49
  • 50. Float (2) â—ŒHow floated elements are positioned 50
  • 51. Clear â—Œclear â–Ș Sets the sides of the element where other floating elements are NOT allowed â–Ș Used to "drop" elements below floated ones or expand a container, which contains only floated children â–Ș Possible values: left, right, both â—Œ Clearing floats â–Ș additional element (<div>) with a clear style 51
  • 52. Clear (2) â—Œ Clearing floats (continued) â–Ș :after { content: ""; display: block; clear: both; height: 0; } â–Ș Triggering hasLayout in IE expands a container of floated elements â–Ș display: inline-block; â–Ș zoom: 1; 52
  • 53. Opacity â—Œopacity: specifies the opacity of the element â–Ș Floating point number from 0 to 1 â–Ș For old Mozilla browsers use –moz-opacity â–Ș For IE use filter:alpha(opacity=value) where value is from 0 to 100; also, "binary and script behaviors" must be enabled and hasLayout must be triggered, e.g. with zoom:1 53
  • 54. Visibility â—Œvisibility â–Ș Determines whether the element is visible â–Ș hidden: element is not rendered, but still occupies place on the page (similar to opacity:0) â–Ș visible: element is rendered normally 54
  • 55. Display â—Œdisplay: controls the display of the element and the way it is rendered and if breaks should be placed before and after the element â–Ș inline: no breaks are placed before and after (<span> is an inline element) â–Ș block: breaks are placed before AND after the element (<div> is a block element) 55
  • 56. Display (2) â—Œdisplay: controls the display of the element and the way it is rendered and if breaks should be placed before and after the element â–Ș none: element is hidden and its dimensions are not used to calculate the surrounding elements rendering (differs from visibility: hidden!) â–Ș There are some more possible values, but not all browsers support them â–Ș Specific displays like table-cell and table-row 56
  • 57. Overflow â—Œ overflow: defines the behavior of element when content needs more space than you have specified by the size properties or for other reasons. Values: â–Ș visible (default) – content spills out of the element â–Ș auto - show scrollbars if needed â–Ș scroll – always show scrollbars â–Ș hidden – any content that cannot fit is clipped 57
  • 58. Other CSS Properties â—Œcursor: specifies the look of the mouse cursor when placed over the element â–Ș Values: crosshair, help, pointer, progress, move, hair, col-resize, row-resize, text, wait, copy, drop, and others â—Œwhite-space – controls the line breaking of text. Value is one of: â–Ș nowrap – keeps the text on one line â–Ș normal (default) – browser decides whether to brake the lines if needed 58