Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheriting from another style in a another style

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

like image 312
Malcolm Avatar asked Jul 22 '09 09:07

Malcolm


People also ask

How do you make a class inherit from another CSS?

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.

Which CSS properties are not inherited?

CSS properties such as height , width , border , margin , padding , etc. are not inherited.

How do you inherit your style?

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.

What is style rule cascading and inheritance?

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.


2 Answers

.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.

like image 197
10goto10 Avatar answered Oct 04 '22 13:10

10goto10


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

like image 5
Philippe Leybaert Avatar answered Oct 04 '22 13:10

Philippe Leybaert