0

Can you select an element with CSS that has a certain id and a certain class?

Something like this I suppose:

#id.class { color: blue; } 
2
  • What's the gain? An id is already supposed to be unique? Commented Jul 10, 2011 at 22:22
  • 1
    @emboss: But an element with an ID isn't guaranteed to have a given class. Commented Jul 11, 2011 at 7:11

1 Answer 1

7

Let's say you have a class people. Their background-color is white. But if you refer to special people like alice or bob, you can use IDs to make them look special.

.people { background-color: white; } .people#alice { text-transform: capitalize; } .people#bob { text-transform: uppercase; } 

What are your intentions? If you want to have a generic people class and special alice and bob you could also use:

CSS:

.people { background-color: white; } #alice { text-transform: capitalize; } #bob { text-transform: uppercase; } 

and HTML:

<div class="people" id="alice">Alice</div> <div class="people" id="bob">Bob</div> 
Sign up to request clarification or add additional context in comments.

2 Comments

Are you saying that when you combine a class and id in a selector like you have, then a period does not precede the classname? I would think your selector would only be applied to <people> elements.
For anyone curious, order of selectors doesn't matter. #id.class and .class#id select exactly the same element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.