The CSS class selector matches element having a specific class name as one of the classes in attribute class. This can be used to specify CSS style based on class name.
Here is the syntax for defining style using class selector.
.classname { style properties } /*all elements having class classname*/ div.classname { style properties } /*div element having class classname*/
Example – style using class selector
<style> /* div.box can also be used to be more specific */ .box { width: 100px; height:100px; background-color: lightgreen; } </style> <div class="box foo bar"> Hello world </div>
Related
- CSS type selectors - define style by element name
- CSS universal selector
- CSS attribute presence and value selectors
- CSS attribute substring selectors
- CSS - style for element having two classes (both)
- CSS id selectors - define style by element id