If have a style like this:
.Style1
{
background-color:white;
}
And a second style like this:
.Style2
{
border: black solid 1px;
}
How do I get Style2
to have Style1
as a base style???
Malcolm
Unfortunately, CSS does not provide 'inheritance' in the way that programming languages like C++, C# or Java do. You can't declare a CSS class an then extend it with another CSS class.
CSS properties such as height , width , border , margin , padding , etc. are not inherited.
The inherit CSS keyword causes the element to take the computed value of the property from its parent element. It can be applied to any CSS property, including the CSS shorthand property all . For inherited properties, this reinforces the default behavior, and is only needed to override another rule.
CSS inheritance refers to the relationship between HTML tags (think parent and children tags) and how certain CSS styles can apply to a tag even though there aren't any CSS rules directly applied to it. Cascading refers to the fact that cumulative styles across multiple CSS rules are applied to each and every HTML tag.
.Style1, .Style2 {
background-color:white;
}
.Style2 {
border: black solid 1px;
}
This way Style1
and Style2
will both have the background set to white, and only Style2
will also have a black border.
There's no inheritance in CSS. The closest you can get to inheritance is by specifying 2 classes in your HTML elements:
<div class="Style1 Style2">..</div>
Or you can simply use the same style name:
.Style1 { background-color:white; }
.Style1 { border: black solid 1px; }
Now Style1 will have both properties
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