Unit 1 CSS
Unit 1 CSS
(CSS)
Introduction
Advantages and disadvantages
Inheretance
CSS basics
Selectors
4 Ways To Put CSS And HTML Together
Introduction
CSS stands for Cascading Style Sheets and
is a simple styling language which allows
attaching style to HTML elements.
Style Sheets are templates, very similar to
templates in desktop publishing applications,
containing a collection of rules declared to
various selectors (elements).
Cascade is a method of defining the weight
(importance) of individual styling rules thus
allowing conflicting rules to be sorted out
should such rules apply to the same selector.
2.
3.
4.
5.
Disadvantages
CSS Inheritance
Allows elements to inherit styles from parent elements.
Helpful in reducing the amount of CSS to set styles for
child elements.
Unless a more specific style is set on a child element,
the element looks to the parent element for its styles.
Each style has a numeric specificity value that is given
based on its selector.
CSS Basics
A style definition is made up of a selector followed by
a declaration block, as shown in this example:
<html>
<head>
<title>CSS Basics</title>
<style type="text/css">
P { color:#000000 }
h1{font-weight: bold; font-style: italic;
color: red}
</style>
</head>
<body>
CSS Syntax
selector/element {
property: value;
}
The selector can either be a grouping of elements, an
indentifier, class, or single XHTML element (body, div,
etc)
Selectors
4 types of selectors
1. Type Selectors
2. Grouping Selectors
3. ID Selectors
4. Class Selectors
Grouping Elements
Allows you to specify a single style for
multiple elements at one time.
h1, h2, h3, h4, h5, h6 {
font-family: Trebuchet MS, sansserif;
}
Embedded Styles
<style type=text/css>
body {}
</style>
Inline Styles
<p style=font-size: 12px>Lorem ipsum</p>
Font Properties
Property
Valid Values
Example
Inherited?
font-family
font-family:
Verdana, Arial;
font-style
normal | italic
font-style:italic;
font-variant
normal | small-caps
font-variant:smallcaps;
font-weight
normal | bold
font-weight:bold;
font-size
[ xx-large | x-large |
large | medium |
small | x-small |
xx-small ] |
[ larger |
smaller ] |
percentage |
length
font-size:12pt;
font
Valid Values
Example
color
color
color: red
background-color
color | transparent
background-color: yellow
background-image
url | none
background-image:
url(house.jpg)
background-repeat
background-attachment
scroll | fixed
background-attachment:
fixed
background-position
background-position: top
center
background
background: silver
url(house.jpg) repeat-y
REFERENCES
FONT ATTRIBUTE
COLOR AND BACKGROUND ATTRIBUTE
TEXT ATTRIBUTE
BORDER ATTRBITEES
MARGIN
LIST ATTRIBUTES
CLASS
<SPAN>