使用 :first-child 伪类向作为其他元素的第一个子元素的元素添加特殊样式。
您可以尝试运行以下代码来了解 :first-child 伪类的用法 -
<html> <head> <style> div > p:first-child { text-indent: 25px; } </style> </head> <body> <div> <p>First paragraph in div. This paragraph will be indented</p> <p>Second paragraph in div. This paragraph will not be indented</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p> </div> <p>But it will not match the paragraph in this HTML:</p> <div> <h3>Heading</h3> <p>The first paragraph inside the div. This paragraph will not be effected.</p> </div> </body> </html>
以上就是CSS 中 :first-child 伪类的用法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号