0
0
CSSmarkup~5 mins

ID selectors in CSS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an ID selector in CSS?
An ID selector targets an HTML element with a specific id attribute. It uses a # followed by the id name to apply styles to that unique element.
Click to reveal answer
beginner
How do you write an ID selector for an element with id="header"?
You write it as #header in your CSS. For example:<br>
#header { background-color: lightblue; }
Click to reveal answer
beginner
Can multiple elements share the same ID in HTML?
No. IDs must be unique within a page. Only one element should have a particular ID to keep styles and scripts predictable.
Click to reveal answer
intermediate
Which has higher priority: an ID selector or a class selector?
An ID selector has higher priority (specificity) than a class selector. This means styles from an ID selector override those from a class selector if both apply.
Click to reveal answer
beginner
Example: What will this CSS do?<br>
#main { color: red; }
It will make the text color red for the element with id="main". Only that element is affected.
Click to reveal answer
How do you select an element with the ID "footer" in CSS?
A#footer
B.footer
Cfooter
D*footer
Can two elements have the same ID in a valid HTML document?
AYes, IDs can be reused
BOnly if they have different classes
CNo, IDs must be unique
DOnly if they are inside different sections
Which selector has higher specificity?
A.menu
B#menu
Cdiv
D*
What symbol is used before the ID name in CSS selectors?
A#
B.
C@
D$
If an element has both an ID and a class, which style will override if both set the same property?
ANeither, they cancel out
BClass style
CThe one declared last
DID style
Explain what an ID selector is and how it is used in CSS.
Think about how you pick a unique item in a group.
You got /4 concepts.
    Describe the difference in priority between ID selectors and class selectors in CSS.
    Which one wins when both apply?
    You got /3 concepts.