WLOP | 北漠
433 words
2 minutes
CSS 常见伪类解析
用户通过勾选/选中元素或取消勾选/取消选中,来改变该元素的
<div> <input type="radio" name="my-input" id="yes"> <label for="yes">Yes</label>
<input type="radio" name="my-input" id="no"> <label for="no">No</label></div>
<div> <input type="checkbox" name="my-checkbox" id="opt-in"> <label for="opt-in">Check me!</label></div>
<select name="my-select" id="fruit"> <option value="opt1">Apples</option> <option value="opt2">Grapes</option> <option value="opt3">Pears</option></select> ()
值得注意的是用 CSS 伪类
<div dir="rtl"> <span>test1</span> <div dir="ltr">test2 <div dir="auto">עִבְרִית</div> </div></div><div> <p>This text is selected!</p> <p>This text isn't selected.</p></div>
<div> <h2>This text isn't selected: it's not a `p`.</h2> <p>This text isn't selected.</p></div>
p:first-child { color: lime; background-color: black; padding: 5px;}
<p>,而不管其在兄弟内的位置如何。
<template> <article> <div>This `div` is first!</div> <div>This <span>nested `span` is first</span>!</div> <div>This <em>nested `em` is first</em>, but this <em>nested `em` is last</em>!</div> <div>This <span>nested `span` gets styled</span>!</div> <b>This `b` qualifies!</b> <div>This is the final `div`.</div> </article></template>
article :first-of-type { background-color: pink;}