4

does anybody know a way or a tool how inheritance can be used in CSS independent of the structure of the elements? Example:

.bg_red { background: red; } .bold { font-weight: bold; } .bg_red_and_bold { //this class should inherit all the properties of the above two classes } 

I hope it is clear what I mean...

Thanks

    5 Answers 5

    6

    There is no way you can do that in CSS, but since you are looking for tools as well, you might look into CSS preprocessing:

    Their mixin and @extend features should do what you are looking for.

      4

      ability to add multiple classes to element is there for exactly that reason.

      <div class="bg_red bold">The red and bold text</div> 
        2

        There is no such thing in CSS. Only thing you can do is:

        .bg_red, .bg_red_and_bold { background: red; } .bold, .bg_red_and_bold { font-weight: bold; } 
          2

          CSS does not support this.

          Consider using LESS, which compiles to CSS and supports mixins:

          .bg_red_and_bold { .bg_red(); .bold(); } 
            0

            Probably not what you want but there is aggregation:

            <div class="bg_red bold"... 

            The div will "inherit" characteristics of both styles.

              Start asking to get answers

              Find the answer to your question by asking.

              Ask question

              Explore related questions

              See similar questions with these tags.