div p matches all <p> elements that are below a <div> element at any depth
div>p matches all <p> elements that are an immediate child of <div> element
under_html = `<div>
<span>
<p> at level 2 under div </p>
</span>
<p> immediately under div </p>
</div>
`
under_css = `/* a <p> anywhere under <div> */
div p {
color: red;
}
/* a <p> immediately under <div> */
div > p {
color: blue;
}
`
tools.sample_from_strings({html: under_html, css: under_css}, {start_with: 'css'})
div + p matches all <p> elements that are immediate right sibling of a <div> element
div ~ p matches all <p> elements that are some right sibling of a <div> element
sibling_html = `<div>
<p>paragraph 1</p>
<div>
<p>child paragraph</p>
</div>
<p>paragraph 2</p>
<p>paragraph 3</p>
</div>
`
sibling_css = `
/* siblings must have the same parent */
/* all <p> immediately after a <div> */
div + p {
color: red;
}
/* all <p> somewhere after a <div> */
div ~ p {
background-color: #ddd;
}
`
tools.sample_from_strings({html: sibling_html, css: sibling_css}, {start_with: 'css', id: 'sibling'})
a first, not-quite-working example (at least on Chrome)
hover1_html = `<div id="part1">
<a href="https://minesparis.psl.eu/" target="_">
a regular link is unsensitive to hovering</a>
</div>
<div class="part2">
<a href="https://minesparis.psl.eu/" target="_">
this one reacts if you hover mouse here</a>
<br>
<a name="minesparis">
this is an anchor tag,
it reacts to mouse presence
(at least on Chrome), that is not what we want</a>
</div>`
hover1_css = `.part2 a:hover {
font-size: 300%; background-color: red;
text-decoration: none;
}
a {
font-size: 200%;
}`
tools.sample_from_strings({html: hover1_html, css: hover1_css}, {start_with: 'css'})
to get it right, we can use the other pseudo-class :link that is set only on <a> tags that have a href= attribute
hover2_html = `<div id="part1">
<a href="https://minesparis.psl.eu/" target="_">
a regular link</a>
</div>
<div class="part2">
<a href="https://minesparis.psl.eu/" target="_">
hover mouse here</a>
<br>
<a name="minesparis">now this anchor tag
is excluded from the CSS selector, so it behaves
as expected</a>
</div>`
hover2_css = `/* <a> elements under a .part2
and that have both pseudo-classes */
.part2 a:hover:link {
font-size: 300%;
background-color: red;
text-decoration: none;
}
a {
font-size: 200%;
}`
tools.sample_from_strings({html: hover2_html, css: hover2_css}, {start_with: 'css'})