tagName#id: use id name plus tag name to mark a style : ID Selector « Style Basics « HTML / CSS






tagName#id: use id name plus tag name to mark a style

  


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
  h2#warning {
   background: red;
  }
  h2#questions {
   background: pink;
  }
  h2#comment {
   background: yellow;
  }
  h2#document {
   background: purple;
  }
  h2#print {
   background: gold;
  }
  h2#search {
   background: gray;
  }
</style>
</head>

<body>

<h2 id="warning">warning</h2> 

<h2 id="questions">question</h2> 

<h2 id="comment">comment</h2> 
  
<h2 id="document">document</h2> 

<h2 id="print">print</h2> 

<h2 id="search">search</h2> 

<p>this is a text.</p>


</body>
</html>

   
  








Related examples in the same category

1.id locator with #
2.An ID should be unique within a document. If it is not, ID will match all elements with the same IDs.
3.To style one paragraph with an extra-large bottom margin of 40 pixels using #paragraph3{margin-bottom:40px;}.
4.Combine the style from ID and class
5.ID Rule Example
6.Set style for DIV targeting id