02.伪元素选择器.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. p{
  10. font-size: 30px;
  11. }
  12. /*
  13. 伪元素:表示页面中一些特殊的并不真实存在的元素(特殊的位置)
  14. 伪元素使用“::”开头
  15. ::first-letter 表示第一个字母
  16. ::first-line 表示第一行
  17. ::selection 表示选中的内容
  18. ::before 表示元素的开始位置(第一个字与标签符号之间的位置)
  19. ::after 表示元素的最后的位置(最后一个字与标签符号之间的位置)
  20. -before和after必须结合content属性来使用
  21. -通过before和after添加的内容,在进行选中操作时不会被选中
  22. */
  23. p::first-letter{
  24. font-size: 50px;
  25. }
  26. p::first-line{
  27. background-color: yellow;
  28. }
  29. p::selection{
  30. background-color: yellowgreen;
  31. }
  32. div::before{
  33. content: 'abc';
  34. color: red;
  35. }
  36. div::after{
  37. content: 'nice';
  38. color: red;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div>Hello Hello World</div>
  44. <p>
  45. Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea consequatur numquam voluptatibus excepturi recusandae molestiae accusamus placeat libero aliquid quis? Rerum ab ut sunt enim minus, nam consectetur exercitationem aliquid.
  46. </p>
  47. </body>
  48. </html>