CSS Priority policy

Source: Internet
Author: User

HTML code
  1. <html>
  2. <head>
  3. <title>testcss</title>
  4. <style type="Text/css">
  5. h2{
  6. color:red;
  7. }
  8. h2{
  9. Color:green;
  10. }
  11. h3{
  12. color:red;
  13. }
  14. h5{
  15. Color:green;
  16. }
  17. </style>
  18. <link rel="stylesheet" type="text/css" href= "A.css"/>
  19. </head>
  20. <body>
  21. <H1 style="Color:red;color:green">1. Green, when the inline way defines Color:red;color:green, whichever is later, the front overlay </H1>
  22. <H2 >2 Green, when the inline way defines two times the color, whichever is later, the previous overlay </h2>
  23. <h3 style="Color:green">3. When defined inline and internal style sheets, inline takes precedence over internal style sheets </h3>
  24. <h4 style="Color:green">4. When you define inline and internal style sheets, inline overrides the internal style sheet, regardless of where the internal style sheet is stored </ H3>
  25. <h5>5. When both an internal style sheet and an external style sheet are defined, the inline style is related to the order defined by the external style sheet, whichever follows, followed by the previous overlay </h5>
  26. </Body>
  27. <style type="Text/css">
  28. h4{
  29. color:red;
  30. }
  31. </style>
  32. </html>

Execution Result:

HTML code
  1. <html>
  2. <head>
  3. <title>testcss</title>
  4. <style type="Text/css">
  5. h1{
  6. Color:green;
  7. }
  8. #h1id {
  9. Color:blue;
  10. }
  11. . h1class{
  12. Color:yellow;
  13. }
  14. #h2id h2{
  15. Color:blue;
  16. }
  17. . H2class h2{
  18. Color:yellow
  19. }
  20. Div h2{
  21. color:red;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. One, inline >>id selector >> class selector >> tag Selector >;: means the first meaning <BR >
  27.             < h1 style= "color:red"  < span class= "attribute" >id= "h1id"  class=" H1class ">1. Red   Inline, tag Selector, class selector, ID selector are compliant, precedence inline </< Span class= "Tag-name" >h1>  
  28.             < h1 style= " id= "h1id"  class= "H1class" >2. Blue   Tag Selector, class selector, ID selector all compliant, priority ID Selector </h1>  
  29. <H1 style="" class="H1class">3. Yellow Tag Selector, class selector compliant, priority class selector </H1>
  30. <H1 style="" >4. Green is ultimately the label selector </H1>
  31. Second, the derivative selector still adheres to the above rule ID derivation >> Class derivation >> Label derivation
  32. <div id="h2id" class="H2class"><h2 >1. Blue </H2 ></div>
  33.               < div            class= "H2class" > <h2>2. Yellow </h2 ></div>  
  34. <div ><h2>3. Red </H2></div&G  T
  35. </Body>
  36. </html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.