1 reply [Last post]
colorrush's picture
Last seen: 5 years 42 weeks ago
Timezone: GMT+1
Joined: 2016-01-29
Posts: 1
Points: 2


Let's say you have a div where there for example is some text in h2, h3 and p tags. Let's say you want to style the h2's and the h3's the same way. If the div class is "container" - the way I would do it now is:

.container h2, .container h3 {
font-size: 16px;

But then I thought, that the ".container" part is there two times.

Is there a smarter way to write it, so that you only write .container once to make the code as short as possible?

Thanks! Smile

gary.turner's picture
Last seen: 38 weeks 6 days ago
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858


I suppose you could use some sort of pre-processor. Of course, that only adds a layer of abstraction that requires you to learn and use another syntax. In the end, your new complication is re-written back to the same syntax you're complaining about.

You'd be messing with the very fabric of time and space and more importantly, making debugging and maintenance more expensive.

CSS is what it is for very good reasons.


If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.