FANDOM


In an HTML document, CSS Class selectors match an element based on the contents of the element's class attribute. The class attribute is defined as a space-separated list of items, and one of those items must match exactly the class name given in the selector. The selector is written by first using the node name of the element, followed by a period, then the name of the class. Example: span.class1. It can also be written simply by stating the class name, without having to have it match an exact element. Example: .class1.


Example:

<html> 
  <head>
    <title>Title</title>
      <style type="text/css">
         span.class1 {
                 background: blue;
         }

         span {
            background: red;
         }

         .other {
             color: green;
         }
      </style>
  </head>
  <body>
    <span class="class1">This text has a blue bg.</span>
    <span>This one has a red one.</span>
    <span class="other">This one has green text.</span>
    <span class="class1 other">This one has a blue bg with green text.</span>
  </body>
</html>

See Also

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.