标签样式

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <style type="text/css">
  5. /*标签样式*/
  6. p{
  7. color:red
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <p>这是段落一</p>
  13. <p >这是段落一</p>
  14. <p >这是段落一</p>
  15. </body>
  16. </html>

类样式

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <style type="text/css">
  5. /*类样式*/
  6. .f20{
  7. font-size:20px;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <p class="f20">这是段落一</p>
  13. </body>
  14. </html>

ID样式

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <style type="text/css">
  5. /*ID样式*/
  6. #f30{
  7. background-color:pink;
  8. font-size:24px;
  9. font-weight:bolder;
  10. font-style:italic;
  11. font-family:"华文彩云";
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p id="f30">这是段落一</p>
  17. </body>
  18. </html>

组合样式

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <style type="text/css">
  5. /*组合样式*/
  6. div p{
  7. color:yellow;
  8. }
  9. div .f32{
  10. font-size:32px;
  11. font-family:"黑体";
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div>
  17. <p><span style="font-size:60px;font-weight:bolder;color:yellow;">HELLO</span></p>
  18. <span calss="f32">World</span>
  19. <p class="f32">!!!</p>
  20. </div>
  21. </body>
  22. </html>

嵌入式样式表

上述四种样式表均为嵌入式样式表

内部样式表

  1. <p><span style="font-size:60px;font-weight:bolder;color:yellow;">HELLO</span></p>

外部样式表

将样式写在css文件内,在html文件中导入css文件

  1. /*ID样式*/
  2. #f30{
  3. background-color:pink;
  4. font-size:24px;
  5. font-weight:bolder;
  6. font-style:italic;
  7. font-family:"华文彩云";
  8. }
  9. /*组合样式*/
  10. div p{
  11. color:yellow;
  12. }
  13. div .f32{
  14. font-size:32px;
  15. font-family:"黑体";
  16. }
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <link rel="stylesheet" href="css/demo01.css">
  5. </head>
  6. <body>
  7. <p>这是段落一</p>
  8. <p class="f20">这是段落一</p>
  9. <p id="f30">这是段落一</p>
  10. <div>
  11. <p><span style="font-size:60px;font-weight:bolder;color:yellow;">HELLO</span></p>
  12. <span calss="f32">World</span>
  13. <p class="f32">!!!</p>
  14. </div>
  15. </body>
  16. </html>