Cascading Style Sheet
Cascading Style Sheet
Cascading Style Sheet
(CSS)
Introduction
HTML
Is primarily concerned with the content
rather than the details of how that content is
presented in the browser.
Tags store the presentation information for
the browser.
Browsers use the default values for those
properties if no values are specified
Prerequisite
Basic word processing using any text
editor.
Developing simple Web Pages using
HTML or XHTML.
What is CSS?
CSS stands for Cascading Style Sheets
Styles define how to display HTML
elements
CSS is used to control the style of a web
document in a simple and easy way.
Styles were added to HTML 4.0 to solve
a problem
External Style Sheets can save a lot of
work, they are stored in CSS files
Why to Learn CSS?
Some of the key advantages of learning CSS:
Create Stunning Web site - 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, layout designs,
variations in display for different devices and screen sizes as well as a
variety of other effects.
Become a web designer - If you want to start a career as a
professional web designer, HTML and CSS designing is a must skill.
Control web - CSS is easy to learn and understand but it provides
powerful control over the presentation of an HTML document. Most
commonly, CSS is combined with the markup languages HTML or
XHTML.
Learn other languages - Once you understands the basic of HTML
and CSS then other related technologies like JavaScript, PHP, or
angular are become easier to understand.
Applications of CSS
CSS is one of the most widely used style language over the web.
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 it 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 a far better look to your HTML page in comparison to
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. So its a good idea to start using CSS in all the
HTML pages to make them compatible to future browsers.
Idea of Style
Idea borrowed from the word processors and
desktop systems
Imposes many styles for the text
CSS
Is used to control the appearance of the web pages
Allows you to associate rules with the elements that
appear in the document
Rule
selector { property : value ;}
Many property-value pairs must be separated by
semicolon.
CSS declaration always ends with a semicolon
Comments in CSS
Comments are used to explain your code, and
may help you when you edit the source code at
a later date. Comments are ignored by
browsers.
A CSS comment begins with "/*", and ends
with "*/", like this:
/*This is a comment*/
p
{
text-align:center;
/*This is another comment*/
color:black;
font-family:arial;
}
Levels of Style Sheet
Eg:
#selection14{ font-size:20pt;}
<h2 id=“selection14”>
The id selector comes here
</h2>
Universal Selector
2. <style type=“text/css”>
li.image{list-style-image:url(cakes.gif);}
</style>
…………..
<li class=“image”> Yummy Cake </li>
3. <style type=“text/css”>
li.disc{list-style-type:disc;}
li.disc{list-style-type:square;}
li.disc{list-style-type:circle;}
</style>
<style type=“text/css”>
.spancolored{font-family:Times New Roman;
color:burlywood;}
</style>
<body>
<p> Notice the difference in the <span
class=“spancolored”> font family and color of the text
</p>
</body>
It is used to group inline-elements in a document.
Provides no visual change by itself.
It provides a way to add a hook to a part of a text or
a part of a document.
When the text is hooked in a span element you can
add styles to the content, or manipulate the content
with for example JavaScript.
<div> tag
It is also applied to a section of document but not to
each paragraph
As with span there is no implied layout for the
content of the <div> tag
Primary use of <div> tag is to give presentation
details for a section or a division of a document.
The <div> tag defines a division or a section in an
HTML document.
The <div> tag is often used to group block-elements
to format them with styles.
Eg:
<div style="color:#00FF00">
<h3>This is a header</h3>
<p>This is a paragraph.</p>
</div>
Difference between <span> and
<div> tag
<span>
Is used for small chunks of in-line HTML
Is in-line tag
<div>
Is a block-tag
Used to group large chunk of code
Allows you to create blocks of content and position
elements on the screen
Introduction
CSS1 givers 60 different properties in
seven categories like
Fonts
Lists
Alignment
Margins
Colors
Backgrounds
Borders etc.
Forms of Property Value
1. Keyword property value
Used when there are only a few possible values
Predefined ones are large, medium, small
They are case sensitive
2. Number values
Used when no meaningful units can be attached to a
numeric property value
Can be integer or a sequence of digits with a decimal
points ,can be preceded by a + or – sign.
3. Length values
Specified as number followed by a two character
abbreviation of a unit name.
Commonly used units are
in – inches , cm-centimeters, mm – millimeter, pt- points,
pc – picas (12 points).
4. Percentage values
Provides a measure that is relative to the previously used
measure for a property value
Are followed by % sign
If preceded by
-plus sign, the percentage is added to the previous
values
-minus sign, the percentage is subtracted from the
previous values
5. URL property values
Can be either be absolute or relative placed in parentheses
preceded by URL
6. Color property values
Can be specified as color names
Color names, RGB, Hexadecimal format.
The Box Model
All documents elements can have borders
Borders have same styles such as color
and width
Elements of Box Model
Outer Edge
Margin
Border
Padding
Inner Edge
Content
The Box Model
Margin - Clears an area around the border. The
margin does not have a background color, it is
completely transparent
Border - A border that goes around the padding
and content. The border is affected by the
background color of the box
Padding - Clears an area around the content. The
padding is affected by the background color of the
box
Content - The content of the box, where text and
images appear
Borders
Every element has a property border-style
This controls whether the element’s content
has a border, with the style of the border
CSS1 requires that the borders be available
for any element – only required style is solid
CSS2 provides several different border styles
dotted, dashed and double(supported by IE7 and
FX2
The styles of one of the four sides of an
element can be set with
border-top-style
border-bottom-style
border-left-style
border-right-style
The border-width property
Specifies the thickness of a border
Possible values are thin, medium, thick or pixel
value in length
Width of each of the four borders of an element
can be different
border-top-width
border-bottom-width
border-left-width
border-right-width
The border-color property
Individual borders of the element can be colored in
CSS2
border-top-color
border-bottom-color
border-left-color
border-right-color
All of the above are supported by IE7 and FX2.
Margins and Padding
The margin property can have from one to four values.
margin:25px 50px 75px 100px;
top margin is 25px
margin:25px 50px;
top and bottom margins are 25px
margin:25px;
all four margins are 25px
Conflict Resolution
What is the problem?
Two different values for the same property
element
Problems with styles
If a property on a particular element has a
property value assigned by some style sheet and
also inherits a value for the same property
Different origins of the specifications of the
property values.
Selector having different levels of precedence
p.special {font-style:italic !important; - (weight )
font-size:14 }
Conflict Resolution
It is a multistage process
Step 1:
Gather the style specifications form the three
possible levels of style sheet
Sort them in order by the relative precedence
of the style sheet levels
Step 2:
All of the available specifications are sorted
by origin and weight
First option : Conflict Resolution rules
1. Important declarations with the user origin
2. Important declarations with author origin
3. Normal declarations with author origin
4. Normal declarations with user origin
5. Any declarations with browser origin
Third Option
Most recently seen specification