cssブラザーセレクター+と〜
隣接する兄弟セレクターは、別の要素の直後に要素を選択でき、両方とも同じ親要素を持ちます。
+と〜には、(。h1 + pと.h1〜p)のように2種類あります。2つの違いは、+は次のp要素のみを選択することです。そして〜は後ろのすべてのp要素を選択します。
+:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
h1+p{
color: blue;
}
</style>
<body>
<div class="father">
<h1>我是一个标题</h1>
<p>我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>
<h2>我是一个标题</h2>
<p>我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>
</div>
</body>
</html>
効果は次のとおりです
。〜:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
h1~p{
color: blue;
}
</style>
<body>
<div class="father">
<h1>我是一个标题</h1>
<p>我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>
<h2>我是一个标题</h2>
<p>我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>
</div>
<div>
<p>我是一个段落</p>
<p>我是一个段落</p>
</div>
</body>
</html>
効果は次のとおりです。
つまり、+は隣り合っていることを意味し、〜はすべての要素を強調します。。