CSS element element 选择器

实例

选择并设置位于 <div> 元素内部的每个 <p> 元素的样式:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. div p {
  6. background-color: yellow;
  7. }
  8. </style>
  9. </head>
  10. <body>
  11. <h2>欢迎来到我的主页</h2>
  12. <div>
  13. <p id="firstname">我是唐老鸭。</p>
  14. <p id="hometown">我住在 Duckburg。</p>
  15. </div>
  16. <p>我最好的朋友是米奇。</p>
  17. </body>
  18. </html>

浏览器支持

选择器
element elementYesYesYesYesYes

所有主流浏览器都支持 element element 选择器。


定义和用法

element element 选择器用于选取元素内部的元素。


相关页面

CSS 教程:CSS 后代选择器

分类导航