Inherit CSS class

后端 未结 9 1233
既然无缘
既然无缘 2020-12-09 07:45

I have one base .base{} in my CSS file with couple properties. I want to change only color and other properties to stay same. How to inherit this base class inother classe

9条回答
  •  长情又很酷
    2020-12-09 07:49

    As others have already mentioned, there is no concept of OOP inheritance in CSS. But, i have always used a work around for this.

    Let's say i have two buttons, and except the background image URL, all other attributes are common. This is how i did it.

    /*button specific attributes*/
    .button1 {
        background-image: url("../Images/button1.gif");
    }
    /*button specific attributes*/
    .button2 {
        background-image: url("../Images/button2.gif");
    }
    
    /*These are the shared attributes */
    .button1, .button2 {
        cursor: pointer;
        background-repeat: no-repeat;
        width: 25px;
        height: 20px;
        border: 0;
    }
    

    Hope this helps somebody.

提交回复
热议问题