Class Selector
1.ID = A person's Identification (ID) is unique to one person.
Class = There are many people in a class.
2.Sometimes it is often confuse to use CSS IDs and CSS Classes in appropriate place.
3.Use IDs when there is only one occurrence per page. Use classes when there are one or more occurences per page.
4.The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements.
5.This allows you to set a particular style for any HTML elements with the same class.
6.The class selector uses the HTML class attribute, and is defined with a "."
To add an extension to the CSS code and make sure to specify this extension in HTML.
<head>
<style type="text/css">
text-align:center;
}
</style>
</head>
<body>
</html>
Center-aligned heading
This is a normal paragraph.
This is a paragraph that uses the p.center CSS code.
<head>
<style type="text/css">
text-align:center;
}
</style>
</head>
<body>
<h1 class="center">This heading will not be affected</h1>
</html>
This heading will not be affected
This paragraph will be center-aligned.
<head>
<style type="text/css">
border-style:solid;
border-color:red;
}
border-style:solid;
border-color:#98bf21;
}
</style>
</head>
<body>
<p class="two">A solid green border</p>
</body>
</html>
A solid red border
A solid green border
Note: The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.
<head>
<style>
color: red;
background-color: blue;
}
</style>
</head>
<body>
</html>
click me
<head>
<style type="text/css">
ul.b {list-style-type:square;}
ol.c {list-style-type:upper-roman;}
ol.d {list-style-type:lower-alpha;}
</head>
<body>
<p>Example of unordered lists:</p>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<p>Example of ordered lists:</p>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
Example of unordered lists:
- Coffee
- Tea
- Coca Cola
- Coffee
- Tea
- Coca Cola
Example of ordered lists:
- Coffee
- Tea
- Coca Cola
- Coffee
- Tea
- Coca Cola
No comments:
Post a Comment