Professional Documents
Culture Documents
ADAVANTAGES OF CSS
UNIT-1 CSS 2
Inline or Attribute style
• Inline styles are used to apply the unique style rules to an element by
putting the CSS rules directly into the start tag. It can be attached to an
element using the style attribute.
• The style attribute includes a series of CSS property and value pairs.
Each "property: value" pair
<h1 style=“color:white;background-color:blue”>Hello</h1>
tag
property
attribute value
UNIT-1 CSS 3
Internal or tag or Embedded style
• Embedded or internal style sheets only affect the document they are
embedded in.
UNIT-1 CSS 5
CSS PROPERTIES
UNIT-1 CSS 6
Color and Background Properties
• The color property defines the text color of an element.
h1 { color: red; }
p { color: purple; }
UNIT-1 CSS 7
• background-color
body { background-color: green; }
• background-image
body { background-image: url(“bg1.gif"); }
• background-repeat
body { background-image: url("images/gradient.png");
background-repeat: repeat-x; }
• background-attachment
body {
background-image: url("images/bell.png");
background-repeat: no-repeat;
background-attachment: fixed;
}
• background-position
body {
background-image: url("images/robot.png");
background-repeat: no-repeat;
background-position: right top;
} UNIT-1 CSS 8
• FONT Properties
• CSS provide several properties for styling the font of the text, including
changing their face, controlling their size and boldness, managing variant, and
so on.
The font properties are:
font-family : to specify the font to be used to render the text
body { font-family: Arial, Helvetica, sans-serif; }
font-style : to set the font face style for the text content of an element
values : normal, italic or oblique.
p{ font-style: oblique; }
font-size : to set the size of font for the text content of an element.
p{ font-size: 20px;}
p {
border: 5px solid red;
}
UNIT-1 CSS 11
• LINK Properties
• A link has four different states — link, visited, active and hover. These four
states of a link can be styled differently through using the following anchor
pseudo-class selectors.
a:link : define styles for normal or unvisited links.
a:visited : define styles for links that the user has already visited.
a:hover : define styles for a link when the user place the mouse pointer over it.
a:active : define styles for links when they are being clicked.
a:link { /* unvisited link */
color: YELLOW;
text-decoration: none;
border-bottom: 1px solid;
}
a:visited { /* visited link */
color: RED;
}
a:hover { /* mouse over link */
color: GREEN;
border-bottom: none;
}
a:active { /* active link */
color: BLUE;
} UNIT-1 CSS 12
• LIST Properties
• CSS provides the several properties for styling and formatting the most
commonly used unordered and ordered lists.
UNIT-1 CSS 13
• CSS Selectors
• A CSS selector is a pattern to match the elements on a web page. The style rules associated
with that selector will be applied to the elements that match the selector pattern.
CSS Element Selector : The Element selector selects the HTML element by name.
p { color: blue; }
CSS ID Selector : The id selector is used to define style rules for a single or unique element.
The id selector is defined with a hash sign (#) immediately followed by the id value.
<style> <body>
#error { <p id="error">This is a
color: #ff0000; warning!</p>
}
</style>
</body>
CSS Class Selector :The class selectors can be used to select any HTML
element that has a class attribute. All the elements having that class will be
formatted according to the defined rule. The class selector is defined with a period
sign (.) immediately followed by the class value.
<style>
.blue { <h1 class="blue">This is a
color: red; heading</h1>
} <p class="blue">This is a
</style> paragraph.</p>
14
UNIT-1 CSS
• CSS Selectors
Global or Universal Selector
CSS universal selectors select any type of elements in an HTML page.
An asterisk ( i.e. "*" ) is used to denote a CSS universal selector. An asterisk
can also be followed by a selector. This is useful when you want to set a style
for of all the elements of an HTML page or for all of the elements within an
element of an HTML page.
* { CSS-Property: value; ........................ }
*{
color: blue; /* color of all the elements should be blue */
background: silver; /* silver background is set for all the
elements */
}
Select all elements inside <div> elements and set their background color
to yellow:
div * {
background-color: yellow;
}
15
UNIT-1 CSS
• CSS BOX MODEL
• All HTML elements can be considered as boxes. In CSS, the term "box
model" is used when talking about design and layout.
• The CSS box model is essentially a box that wraps around every HTML
element. It consists of:
margins, borders, padding, and the actual content
16
UNIT-1 CSS
• CSS BOX MODEL
Margin - Clears an area outside the border. The margin is transparent
Border - A border that goes around the padding and content
Padding - Clears an area around the content. The padding is transparent
Content - The content of the box, where text and images appear
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey; width: 300px; border: 15px solid green;
padding: 50px; margin: 20px; }
</style>
</head>
<body>
<h2>Demonstrating the Box Model</h2>
<p>The CSS box model is essentially a box that wraps around every HTML element. It
consists of: borders, padding, margins, and the actual content.</p>
<div>
Content
</div>
</body>
</html> 17
UNIT-1 CSS
• CSS POSITION PROPERTY
The CSS position property defines the position of an element in a document.
This property works with the left, right, top, bottom and z-index properties to
determine the final position of an element on a page.
position: value;
Value Description
Normal position for the element (where top, right,
static bottom, and left have no effect)
div { position: static; }
18
UNIT-1 CSS
• CSS CURSOR PROPERTY
The cursor property specifies the mouse cursor to be displayed when pointing
over an element.
cursor: value;