Intro
To assign styles to html elements we need to be able to "select" the relevant elements. We do this with CSS Selectors.
Selectors
- Attribute Selector []
- A Way to specifically target an element's attribute. Attributes are things such as ID, or Class, or "draggable". If we had one, (or more) <p> element(s) with an ID of "priority":
- <p id="priority">This paragraph has priority</p>
- p[#priority] {}
- A Way to specifically target an element's attribute. Attributes are things such as ID, or Class, or "draggable". If we had one, (or more) <p> element(s) with an ID of "priority":
- Group Selector , (comma)
- Allows us to target multiple elements. If we have an <h1> and an <h2> element that we want to select, we would use:
- h1, h2 {}
- Allows us to target multiple elements. If we have an <h1> and an <h2> element that we want to select, we would use:
- Direct Descendant, or Child Selector > (greater than)
- Allows us to select all descendant element(s), that are a direct descendant. If we had a <div> with descendant <p> element(s), we could select the descendants, like so:
- div > p {}
- Allows us to select all descendant element(s), that are a direct descendant. If we had a <div> with descendant <p> element(s), we could select the descendants, like so:
- All Descendant Selector (space)
- Selects ALL of the descendant elements specified, of the parent element. So, if we have a <div> element, and inside are a couple of <p> elements, and a <ul> with a <p> element, if we select:
- div (space) p {}
- Selects ALL of the descendant elements specified, of the parent element. So, if we have a <div> element, and inside are a couple of <p> elements, and a <ul> with a <p> element, if we select:
- Chaining
- Chaining is a way of being very specific in our element selection process. Let's say we have an <h1> with an ID of title, and two classes (class1, & class2):
- <h1 id="title" class="class1 class2">
- h1#title.class1.class2
- Chaining is a way of being very specific in our element selection process. Let's say we have an <h1> with an ID of title, and two classes (class1, & class2):