0

I have this declaration:

.myClass td, .myClass tr, .myClass table, .myClass img {margin:0, padding:0;}

I do not want to repeat ".myClass", I would rather write it as something like below:

.myClass (td, tr, table, img) {margin:0, padding:0;}

I know the above is not correct, so how would I achieve this in correct syntax?

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
  • 2
    With CSS you can't; with [tag:less] or [tag:sass] you can. – David Thomas May 27 '14 at 18:21
  • Thank you, but less or sass are preprocessors that will yield the same result on the final page/css file, correct? I was thinking if there is a way to have this as the end result, but I assume I cannot. – user3680941 May 28 '14 at 09:30

1 Answers1

0

.myClass > * { margin:0;padding:0; }

Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • That won't affect `.myClass tr td` only immediate children of `.myClass` but you should also add a disclaimer that it will affect all elements inside that one without the `>`. –  May 27 '14 at 18:22
  • You can make it `.myClass *` and that will work. – tim May 27 '14 at 18:23
  • Thank you, but this is **not** what I want. I do not want **all** children to get that style but just the ones I mention above (tr,td, etc.). So, the question still holds, does CSS has any rule to allow for that in a shorter syntax? (than just repeating the .myClass for each child element?) – user3680941 May 28 '14 at 09:29