Professional Documents
Culture Documents
An Introduction
•Cascading Style Sheets (CSS) form the presentation layer of
the user interface.
Structure (XHTML)
Behavior (Client-Side Scripting)
Presentation (CSS)
<html>
<body>
<h1 style="color:blue;margin-left:30px;">This is a
heading.</h1>
<p>This is a paragraph.</p>
</body>
</html>
Embedded Style Sheets(internal)
• this method can only specify style information for the current
document
• embedded style sheet rule will have higher precedence than
external style sheet rule, if there is a conflict between styles
• embedded style sheet rule will have lower precedence than
an inline style sheet rule.
• Embed an entire CSS document in an XHTML document’s
head section inside a style element
– Attribute type
• Multipurpose Internet Mail Extensions (MIME) type
– describes the type of the document’s content
– text/css is the type for CSS document
Parts of a Rule
• Selector:
– “selects” what will be modified
– Simplest selector would be a tag
• <p>, <h1>, etc.
• Property:
– What is going to be changed
– You already know things like color, font-size, etc.
– Can have any number of properties
• Value:
– Specifies what the value of the property should be changed to
– For instance changing the color to “red”
The general form of style element
<style type=“text/css”>
Rule_list
</style>
Style Rule
Mystyle.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<html><head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
SELECTOR FORMS
1.Simple selectors
• Single element name.
• Rule apply to all occurrences' of named element.
- h1{font-size:24pt;}
*{color:red;}
6.Pseudo classes
• A pseudo-class is used to define a special state of an element.
• Begin with colons.
For example, it can be used to:
Style an element when a user mouses over it
Style visited and unvisited links differently
Style an element when it gets focus
syntax
selector:pseudo-class {
property:value;
}
Ex:
a:hover {
color: #FF00FF;
}
a:visited {
color: #00FF00;
}
Input:hover{color:red}
Input:focus{color:green;}