E:only-child …… 子として唯一となるE要素
広告
E:only-childは、疑似クラスの一種で、
子として唯一となるE要素にスタイルを適用する際に使用します。
- 書式
- E:only-child {プロパティ名:値;}
- 適用対象
- 子として唯一となるE要素
p.sample strong:only-child {background-color:navy; color:white;}
<html>
<head>
<link rel="stylesheet" type="text/css" href="sample.css">
</head>
<body>
<p class="sample">
明日は<strong>雨</strong>でしょう。
気温が低くなるでしょう。
長袖の上着があると良いでしょう。
</p>
<p class="sample">
明日は<strong>雨</strong>でしょう。
<span>気温が低く</span>なるでしょう。
<span>長袖の上着</span>があると良いでしょう。
</p>
<p class="sample">
明日は<strong>雨</strong>でしょう。
<strong>気温が低く</strong>なるでしょう。
<strong>長袖の上着</strong>があると良いでしょう。
</p>
</body>
</html>
↓↓↓
明日は雨でしょう。
気温が低くなるでしょう。
長袖の上着があると良いでしょう。
明日は雨でしょう。
気温が低くなるでしょう。
長袖の上着があると良いでしょう。
明日は雨でしょう。
気温が低くなるでしょう。
長袖の上着があると良いでしょう。
広告