CSS :only-child 選擇器的作用
使用 CSS :only-child 選擇器對作為其父元素唯一子元素的所有 <p> 元素進行樣式設定。
示例
您可以嘗試執行以下程式碼來實現 :only-child 選擇器
<!DOCTYPE html>
<html>
<head>
<style>
p:only-child {
background: orange;
}
</style>
</head>
<body>
<h1>Heading</h1>
<div>
<p>This is a paragraph.</p>
</div>
<div>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</div>
</body>
</html>
廣告
資料結構
網路技術
關係型資料庫管理系統
作業系統
Java 程式語言
iOS 系統
HTML 語言
CSS 語言
Android 系統
Python 程式語言
C 程式語言
C++ 程式語言
C# 程式語言
MongoDB 資料庫
MySQL 資料庫
JavaScript 語言
PHP 語言