How do I avoid redefining the parent element class

2019-07-20 06:11发布

问题:

I have a CSS block similar to that below which defines common styles for element-a[ace]:

.element-a .element-aa, .element-a .element-ac, .element-a .element-ae {
     /* ... some styling */
}

Is it possible to avoid redefining element-a or a neater way of doing it all together.

回答1:

try the following .element-a div[class*='element-a']. The above example presuppose that the descendant class is applied in a div, of course you can change it to whatever you use.

Demo: http://jsfiddle.net/yPBcR/1