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 语言