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>:only-child</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 :only-child {
\r
19 background-color: #090;
\r
22 .defaultgreen :only-child {
\r
23 background-color: #900;
\r
31 <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
33 <div class='base'></div>
\r
37 <div class='defaultred'>
\r
38 <div class='test required'></div>
\r
41 <pre>div :only-child {
\r
45 <div></div>
\r
49 The CSS selector should match the inner div element, because it is the only child of the outer div element
\r
54 <div class='defaultred'>
\r
55 <div class='test'></div>
\r
56 <!-- Just a comment -->
\r
59 <pre>div :only-child {
\r
63 <div></div>
\r
64 <!-- Just a comment -->
\r
68 The CSS selector should match the inner div element, because it is the only child of the outer div element
\r
73 <div class='defaultred'>
\r
74 <div class='test'></div>
\r
78 <pre>div :only-child {
\r
82 <div></div>
\r
83 How about regular text...
\r
87 The CSS selector should match the inner div element, because it is the only child of the outer div element
\r
92 <div class='defaultgreen'>
\r
93 <div class='test default required'></div>
\r
94 <blockquote></blockquote>
\r
97 <pre>div :only-child {
\r
101 <div></div>
\r
102 <blockquote></blockquote>
\r
106 The CSS selector should not match the inner div element, because it not the only child
\r
112 <div class='defaultgreen'>
\r
113 <div id='appendChild' class='test default'></div>
\r
116 <script type="text/javascript">
\r
119 var ib = document.getElementById('appendChild');
\r
120 ib.parentNode.appendChild(document.createElement("div"));
\r
125 <pre>div :only-child {
\r
129 <div id='appendChild'></div>
\r
132 var ib = document.getElementById('appendChild');
\r
133 ib.parentElement.appendChild(document.createElement("div"));</pre>
\r
136 The CSS selector should not match the original div element, because it is
\r
137 not the only child anymore after another child is append by the Javascript code.
\r