1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
\r
5 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
\r
6 <title>:first-of-type</title>
\r
8 <style type='text/css'>
\r
11 body { background: #fff; color: 000; font-family: Arial, Helvetica, sans-serif; }
\r
12 pre { background: #fff; padding: 0.5em; }
\r
13 li { background: #aaa; padding: 1em; width: 80%; margin: 0 0 3em; }
\r
14 .test { display: block; padding: 0.75em; }
\r
15 .base, .defaultgreen { background-color: #090; }
\r
16 .defaultred { background-color: #900; }
\r
18 .defaultred :first-of-type {
\r
19 background-color: #090;
\r
22 .defaultgreen :first-of-type {
\r
23 background-color: #900;
\r
35 <p>This page is part of the <a href="http://www.css3.info">CSS3.info</a> <a href="http://www.css3.info/selectors-test/">CSS selectors test</a>. See more info on <a href="http://www.css3.info/preview/attribute-selectors.html">CSS3 selectors</a>.</p>
\r
37 <div class='base'></div>
\r
41 <div class='defaultred'>
\r
42 <div class='test required'></div>
\r
45 <pre>div:first-of-type {
\r
48 <div>Does this element match?</div></pre>
\r
51 The CSS selector should match the marked div element, because it is the only element of this type
\r
56 <div class='defaultred'>
\r
57 <div class='test'></div>
\r
61 <pre>div:first-of-type {
\r
64 <div>Does this element match?</div>
\r
65 <div></div></pre>
\r
68 The CSS selector should match the marked div element, because it is the first element of this type
\r
73 <div class='defaultred'>
\r
74 <blockquote></blockquote>
\r
75 <div class='test required'></div>
\r
78 <pre>div:first-of-type {
\r
81 <blockquote></blockquote>
\r
82 <div>Does this element match?</div></pre>
\r
85 The CSS selector should match the marked div element, because it is the first element of this type
\r
90 <div class='defaultred'>
\r
93 <div class='test'></div>
\r
97 <pre>div:first-of-type {
\r
100 <div></div>
\r
102 <div>Does this element match?</div>
\r
103 </blockquote></pre>
\r
106 The CSS selector should match the marked div element, because it is the first element of this type in this scope
\r
111 <div class='defaultred'>
\r
113 <div class='test'></div>
\r
117 <pre>div:first-of-type {
\r
121 <div>Does this element match?</div>
\r
125 The CSS selector should match the marked div element, because it is the first element of this type in the current scope
\r
130 <div class='defaultred'>
\r
134 <div class='test'></div>
\r
137 <pre>div:first-of-type {
\r
141 <div></div>
\r
142 </blockquote>
\r
143 <div>Does this element match?</div></pre>
\r
146 The CSS selector should match the marked div element, because it is the first element of this type in the current scope
\r
151 <div class='defaultgreen'>
\r
153 <div class='test default required'></div>
\r
156 <pre>div:first-of-type {
\r
159 <div></div>
\r
160 <div>Does this element match?</div></pre>
\r
163 The CSS selector should not match the marked div element, because it is the second element of this type
\r
168 <div class='defaultgreen'>
\r
170 <div class='test default'></div>
\r
173 <pre>div:first-of-type {
\r
176 <DIV></DIV>
\r
177 <div>Does this element match?</div></pre>
\r
180 The CSS selector should not match the marked div element, because it is the second element of this type
\r
185 <div class='defaultred'>
\r
186 <div id='insertBefore1'></div>
\r
189 <script type="text/javascript">
\r
192 var ib = document.getElementById('insertBefore1');
\r
193 var el = document.createElement("div");
\r
194 el.className = 'test';
\r
195 ib.parentNode.insertBefore(el, ib);
\r
201 <pre>div:first-of-type {
\r
204 <div id='insertBefore'></div>
\r
206 var ib = document.getElementById('insertBefore');
\r
207 ib.parentElement.insertBefore(document.createElement("div"), ib);</pre>
\r
210 The CSS selector should match the div element that is inserted by the Javascript code.
\r
215 <div class='defaultgreen'>
\r
216 <div id='insertBefore2' class='test default'></div>
\r
219 <script type="text/javascript">
\r
222 var ib = document.getElementById('insertBefore2');
\r
223 ib.parentNode.insertBefore(document.createElement("div"), ib);
\r
228 <pre>div:first-of-type {
\r
231 <div id='insertBefore'></div>
\r
233 var ib = document.getElementById('insertBefore');
\r
234 ib.parentElement.insertBefore(document.createElement("div"), ib);</pre>
\r
237 The original div element should not be a match for the :first-of-type selector.
\r