Cascading Style Sheet
Cascading Style Sheet
Cascading Style Sheet
Cascading Style
Sheets
• Allow the specification of the style of the
page separately from the structure and
content
– spacing, margins, fonts
– the look and feel
• styles definehow to display HTML elements
• styles are stored inStyle Sheets
• multiple style definitions will cascade into
one
• Allows better management
• Makes changing style easier
Cascading Style
Sheets
• Cascading Style Sheet is a simple, declarative
language that allows authors and users to apply
stylistic information to structured documents written
in HTML or XML.
• World Wide Web Consortium (W3C):
– CSS1 (1996);
– CSS2 (1998);
– CSS3 (2001)
– CSS4(2007)
• Netscape and Microsoft Corporations;
• Internet Explorer (IE) and Netscape Navigator (NN)
supports styles.
Advantages and
Disadvantages
• Advantages:
– Greater typography and page layout controls
– Easier site maintenance
– The style sheet information can be stored
separate from your HTML document, and shared
among many HTML files. Change one style sheet
file, and the appearance of the entire site is
updated.
• Disadvantages
– Browser compatibility must be the most common
difficulty.
Why?
• to save a lot of work and our time;
• easier to handle and edit web
documents;
• easier to control content and layout of
the multiple web sites.
The order of the cascading
• External Style Sheet
• Internal Style Sheet
• Inline Style
Inline Style
• is used inside the HTML tags:
• Each CSSproperty is followed by a colon then the value of the
attribute
• Properties are separated by semicolons
• The STYLEattribute allows the specification of a style property
<p style="color: green"> First Paragraph </p>
Example :
<HTML><BODY>
<P>Some Text - just plain</P>
in HTML document:
<p class=“center”>Paragraph</p>
• HTML
– …
– <h1 class=“red”>Headline</h1>
– <p class=“red”>a summary</p>
– <p class=“blue”>some text</p>
– …
Class Attribute
• Used when an HTML element can display more than one
behaviour (e.g. hyperlinks)
• CSS:
• HTML
• HTML
…
<h1 id=“red_heading”>Headline</h1>
<p id=“summary”>Summary</p>
<p id=“conclusion”>Conclusion</p>
…
Grouping
you can group selectors:
h1, h2, h3 {color: maroon}
h4 {color: green}
Note:
each selector has been separated with a
comma.
The Golden Rules for Styles
• Element Names are always case-insensitive.
HTML
• Attribute Names are always case-insensitive.
HTML
• Attribute Values are generally case-insensitive.
HTML
• CLASS Names are case-sensitive. HTML /
CSS Style
• ID Names are case-sensitive. HTML / CSS
Style
Comments
are used for the explaining the code.
It can help to edit the code later:
/* Comment */
p {text-align: center; font-family: arial}