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.
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; }You can also select elements (or classes) that's nested within another element or class. For example, div.css-section p will select all
elements that are nested within a <div> element that uses the .css-section class.
One major benefit of doing this is that you don't need to apply a class to every instance of an element when it's nested within another element that uses a class.
Comments
Post a Comment