CSS Class
In CSS, classes allow you to apply a style to a given class of an element. To do this, you link the element to the style by declaring a style for the class, then assigning that class to the element.
CSS Class Syntax
You declare a CSS class by using a dot (.) followed by the class name. You make up the class name yourself. After the class name you simply enter the properties/values that you want to assign to your class.
.class-name { property:value; }
If you want to use the same class name for multiple elements, but each with a different style, you can prefix the dot with the HTML element name.
html-element-name.class-name { property:value; }
CSS Class Example
<head> <style type="text/css"> h1.css-section { color:#000099 } p.css-section { color:#999999; } </style> </head> <body> <h1 class="css-section">CSS Class</h1> <p class="css-section">CSS classes can be very useful</p> </body>
This results in:
CSS Class
CSS classes can be very useful
Cascading Rules of Classes
If you have already applied a style to an element, the element will first use those styles, then the ones defined in the class.
Comments
Post a Comment
leave your comment to help us to develope the website.