css-intro
css-intro
Selector Declaration
Value
Attribute
1. Element Selector
used to select an element for styling.
Example:
P
{
text-align:right;
color: blue;
}
2. Id Selector
• Id selectors are used to do styling of selected Id’s.
Example:
#paragraph1
{
text-align: right;
color : blue;
}
3. Class Selector
• Used for styling of particular class.
Example:
.class1
{
text-align: center;
color: blue;
}
Group Selector
• Group selectors used for styling of multiple
elements or selectors.
Example:
h1,h2,P
{
text-align: center;
color: blue;
}
• There are three ways of inserting
a style sheet:
Inline CSS
Internal CSS
External CSS
Inline Styling
• An inline style may be used to apply a unique style for a
single element.
Example:
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;text-align:center;">Welcome</h1>
</body>
</html>
Internal CSS
• An internal style sheet may be used if one single HTML page has a unique style.
• The internal style is defined inside the <style> element, inside the head section.
Example:
<!DOCTYPE html>
<head>
<style>
body {
background-color: blue;
}
h1 {
color: red;
margin-left: 20px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
External CSS
• With an external style sheet, the look of an entire website can be changed by
changing just one file!
• Each HTML page must include a reference to the external style sheet file inside the
<link> element, inside the head section.
Example:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href=“style.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External File :“style.css”
Body{
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}