Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use class within another class in css?


Asked by Rosa Cooper on Nov 30, 2021 CSS



For demonstration purposes, if we want to apply the same effect to all h1, independent of class: You can use any CSS selector while nesting with spaces, you can use id selectors with #id-name, tag selectors like h1, pseudo-classes, etc.
Besides,
Classes are used by CSS and JavaScript to select and access specific elements; The class attribute can be used on any HTML element; The class name is case sensitive; Different HTML elements can point to the same class name; JavaScript can access elements with a specific class name with the getElementsByClassName() method
One may also ask, The best way (that I know of) to re-use css classes is to decide on the css attributes you want to re-use, and put this in a seperate class, like so: Then, every time you want to re-use these attributes, you add the class to the html element, with spaces in between different class names, like so:
Subsequently,
The second targets the same element, but overrides the color, instead of having to use: or perhaps prefacing the selector with something even more specific. More useful is multiple classes and using them in the “object oriented” css style that is all the rage lately.
In this manner,
To define multiple classes, separate the class names with a space, e.g. <div class="city main">. The element will be styled according to all the classes specified. In the following example, the first <h2> element belongs to both the city class and also to the main class, and will get the CSS styles from both of the classes: