-2

I have two CSS rules with different selectors which I want to combine. Both rules have the same CSS properties. The first selector targets th elements, and the other selector targets td elements:

.MyClass th:nth-child(n+6):nth-child(-n+9){
    text-align: right;
}

.MyClass td:nth-child(n+6):nth-child(-n+9){
    text-align: right;
}

I suppose it is possible to combine these two rules, but how?

EDIT

Okey, I know I put my answer in wrong. My question is a little to simple!

I already was aweare of putting them together with a comma like this:

.MyClass th:nth-child(n+6):nth-child(-n+9),
.MyClass td:nth-child(n+6):nth-child(-n+9){
    text-align: right;
}

But what I actually wanted to know is how to only do a single selector of :nth-child(n+6):nth-child(-n+9).

7
  • 1
    by putting them next to each other seperated by comma? Commented Sep 17, 2013 at 7:02
  • Gosh I hate when an answer is so easy, and I keep putting comments. Commented Sep 17, 2013 at 7:03
  • Put it as an answer then... ;-) Commented Sep 17, 2013 at 7:04
  • It is kind of too late now :D I wont get the credit for it, how rude. Commented Sep 17, 2013 at 7:05
  • Or actually contribute to the site and mark it as a duplicate. Commented Sep 17, 2013 at 7:06

2 Answers 2

3

Did you try

.MyClass th:nth-child(n+6):nth-child(-n+9), 
.MyClass td:nth-child(n+6):nth-child(-n+9) {
    text-align: right;
}
Sign up to request clarification or add additional context in comments.

2 Comments

This works, thanks. But I hoped for a shorter version! I will change my question.
@Timo002 don't change, post another....
3

Use a comma , separator, here is a sample

.class1, .class2 {
   text-align: right;
}

1 Comment

I don't know why a downvote here?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.