[[CSS Selectors]]
Created: 2022-10-06
h1 {
}
.box{
}
#unique {
}
This group of selectors gives you different ways to select elements based on the presence of a certain attribute on an element:
a[attribute="value"] {
}
Or even make a selection based on the presence of an attribute with a particular value:
a[href="https://example.com"] {
}
Selects only when to apply the css rules base on the condition it is in
Below will only take effect when link is in hover
a:hover {
}
Selects a certain part of an element to be modified
This only takes effect on the first line of a <p> element
p::first-line {
}
The following, selects <p> that are direct children of <article> elements using the child combinator (>):
article > p {
}
To select only an <em> that is nested inside an <li> element,
You can use a selector called the
li em {
color: rebeccapurple;
}
Something else you might like to try is styling a paragraph when it comes directly after a heading at the same hierarchy level in the HTML.
To do so, place a + the selectors.
h1 + p {
font-size: 200%;
}