CSS Selectors Flashcards
What selector can you use to to apply CSS styling to every element on the page
The Universal Selector. e.g. * {
border: 2px solid black;
}
What can you think of an HTML document like?
A tree where elements branch out from the Trunk
An element is a child of what?
An element is a child of EVERY element wrapped around it, even if that element is several “branches” away!
The Tag is like a what on a tree
Trunk
What are the immediate branches of the HTML tag or Trunk
Head and Body or it’s children
How can you grab direct children—that is, an element that is directly nested inside another element, with no elements in between
> e.g. div > p { /* Some CSS */ }
When will certain selectors override others?
if they have a greater specificity value. ul li p { is more specific CSS than just p {, so when CSS sees tags that are both <p> tags and happen to be inside unordered lists, it will apply the more specific styling (ul li p {) to the text inside the lists.
What are the two selectors that are more specific than nested selectors?
Classes and IDs
How are classes assigned to elements?
with the word class and an equals sign. <div class="square"></div>
How are classes identified in CSS
With a dot.
When is it a good idea to use an ID
When there is ONE element that needs styling
How are IDs assigned
With the word id and the =
e.g. <div></div>
How are IDs identified?
With a # sign. e.g. #serious
What is a pseudo-class selector?
way of accessing HTML items that aren’t part of the document tree
What’s a use case for a pseudo-class selector
you can control the appearance of unvisited and visited links—even links the user is hovering over but hasn’t clicked!