使用 CSS 选择所有父元素为 div 元素的元素
cssweb developmentfront end technology更新于 2024/7/23 0:44:17
使用 element > element 选择器选择具有父元素的元素。
您可以尝试运行以下代码,选择所有父元素为 <div> 元素的 <p> 元素。
示例
<!DOCTYPE html>
<html>
<head>
<style>
div > p {
color: white;
background-color: blue;
}
</style>
</head>
<body>
<h1>Demo Website</h1>
<h2>Fruits</h2>
<p>Fruits are good for health.</p>
<div>
<p>This is demo text.</p>
</div>
</body>
</html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

