Quick question which is mostly explained by the code.
Is this possible in CSS or do I have to just implement all the classes in the html?
.class1{
color:red;
}
.class2{
text-decoration:underline;
}
.class3{
class1;
class2;
border:1px solid green;
}
You can write the CSS styles to a specific element or group elements together with a specific style. Grouping CSS styles saves page space and allows you to apply particular styles to multiple tags.
Direct Nesting. A style rule can be directly nested within another style rule if its selector is nest-prefixed. To be nest-prefixed , a nesting selector must be the first simple selector in the first compound selector of the selector.
Attribute Values 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.
The CSS Grouping Selector The grouping selector selects all the HTML elements with the same style definitions. It will be better to group the selectors, to minimize the code. To group selectors, separate each selector with a comma.
You can use a CSS pre-processor like LESS or SASS for CSS "class inheritance".
Otherwise, your code sample is not possible with pure CSS. You can, however, use a comma to add similar styles to multiple elements:
.class1, .class2 {
/* your styles */
}
It is not possible to do it as such. If an element needs to have multiple classes, just specify it in the HTML :
<span class="class1 class2">Test</span>
Note that it is possible to define a selector for elements having multiple classes. .class1.class2
selector would target the element in the example here above, while not targetting elements that don't have both classes specified in HTML. This is usefull for example if you wish to override one of the properties of 1 of the classes only when they're used in combination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With