CSS 中的子选择器

cssweb developmentfront end technology更新于 2025/1/5 0:12:17

CSS 子选择器用于选择具有特定父元素的所有子元素。

语法

CSS 子选择器的语法如下−

element > element {
/*declarations*/

示例

以下示例说明了 CSS 后代选择器 −

<!DOCTYPE html>
<html>
<head>
<style>
* {
   padding: 5px;
}
article > div {
   border: dashed midnightblue;
   width: 45%;
}
div > p {
   font-size: 20px;
   font-style: italic;
   box-shadow: inset 0 0 8px orange;
}
</style>
</head>
<body>
<h2>Examination Detail</h2>
<article>
   <div>Exam Details</div>
   <div><p>Exam begins at 11AM.</p></div>
   <span><div> Do not bring cell phone.</div></span>
   <div>
   <div>Candidates should reach the center till 10:45.</div>
   <br/>
   The candidates need to be bring the Admit Card.
   </div>
</article>
</body>
</html>

输出

这将给出以下输出

示例

<!DOCTYPE html>
<html>
<head>
<style>
div {
   margin: auto;
   width: 200px;
   padding: 30px;
   background-color: moccasin;
}
div > div {
   box-shadow: inset 0 0 8px mediumseagreen;
   border-top-right-radius: 50%;
   border-bottom-left-radius: 50%;
}
</style>
</head>
<body>
<div>
<div></div>
</div>
</body>
</html>

输出

这将给出以下输出


相关文章


有用资源