Selector | Description | |
---|---|---|
|
Simple selectors |
|
p | tag name | selector |
#carbon | id | selector |
.chimica | class | selector |
span.chimica | to specify which HTML elements select | |
h1, h2, p | To group selectors, separate each selector with a comma. | |
Combinator selectors |
||
div p elm elm |
descendant selector (space) selects all elements that are descendants of a specified element. es: all p elements inside a div element |
|
div > p elm > elm |
child selector (>)selects
all elements that are the children of a specified element es: all p elements children of a div element |
|
div + p elm + elm |
immediately after selector (+) selects all elements that are immediately after of a specified element. es: all p elements immediately after a div element |
|
div ~ p elm ~ elm |
siblings_after selector (~) selects all sibling elements after of a specified element. es: all siblings p elements after a div element |
w3/Level 3 Selectors specification
Selectors, in particolare Types of selectors.
Piu' in generale, il modulo cui appartiene questo capitolo >>>
to select an element with a specific id, write a hash (#) character, followed by the id of the element.
<style>
#myHeader {
background-color: lightblue;
color: black;
}
</style>
<h1 id="myHeader">My Header</h1>
select the element after (not inside) the first specified element.
span:hover + div {
display: block;
}