50 likes | 189 Views
CSS: Class Attribute. BCS-AWD-7. CSS: Definition and Usage. The Class Attribute is used when you want to identify elements that share a common characteristic.
E N D
CSS: Class Attribute BCS-AWD-7
CSS: Definition and Usage • The Class Attributeis used when you want to identify elements that share a common characteristic. • The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.
CSS: Definition and Usage • To assign an element to a class, add the attribute class=”classname”to the element’s markup tag, where classname is the name of the class. • To apply a style to a class of elements, use the selector .classnamewhere classnameis the name of the class. • To apply a style to an element of a particular class, use the selector elem.classnamewhere elem is the name of the element and classnameis the name of the class.
CSS: Definition and Usage Syntax: <elem class=“classname”>…..</elem> Classname: Specifies one or more class names for an element. To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.
CSS: Definition and Usage Class Naming rules: • Must begin with a letter A-Z or a-z • Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_") • In HTML, all values are case-insensitive