<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
<title>:last-child</title> | |
<style type='text/css'> | |
<!-- | |
body { background: #fff; color: 000; font-family: Arial, Helvetica, sans-serif; } | |
pre { background: #fff; padding: 0.5em; } | |
li { background: #aaa; padding: 1em; width: 80%; margin: 0 0 3em; } | |
.test { display: block; padding: 0.75em; } | |
.base, .defaultgreen { background-color: #090; } | |
.defaultred { background-color: #900; } | |
.defaultred :last-child { | |
background-color: #090; | |
} | |
.defaultgreen :last-child { | |
background-color: #900; | |
} | |
blockquote { | |
margin: 0; | |
} | |
--> | |
</style> | |
</head> | |
<body> | |
<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> | |
<div class='base'></div> | |
<ol> | |
<li> | |
<div class='defaultred'> | |
<div class='test required'></div> | |
</div> | |
<pre>div :last-child { | |
} | |
<div> | |
<div></div> | |
</div></pre> | |
<p> | |
The CSS selector should match the inner div element, because it is the only child of the outer div element | |
</p> | |
</li> | |
<li> | |
<div class='defaultred'> | |
<blockquote></blockquote> | |
<div class='test'></div> | |
</div> | |
<pre>div :last-child { | |
} | |
<div> | |
<blockquote></blockquote> | |
<div></div> | |
</div></pre> | |
<p> | |
The CSS selector should match the inner div element, because it is the last child of the outer div element | |
</p> | |
</li> | |
<li> | |
<div class='defaultred'> | |
<!-- Just a comment --> | |
<div class='test'></div> | |
</div> | |
<pre>div :last-child { | |
} | |
<div> | |
<div></div> | |
<!-- Just a comment --> | |
</div></pre> | |
<p> | |
The CSS selector should match the inner div element, because it is the last child of the outer div element | |
Comments are not elements, so they should not be considered when determining the last child. | |
</p> | |
</li> | |
<li> | |
<div class='defaultred'> | |
<div class='test'></div> | |
. | |
</div> | |
<pre>div :last-child { | |
} | |
<div> | |
<div></div> | |
How about regular text... | |
</div></pre> | |
<p> | |
The CSS selector should match the inner div element, because it is the last child of the outer div element. | |
Regular text is not an element, so it should not be considered when determining the last child. | |
</p> | |
</li> | |
<li> | |
<div class='defaultgreen'> | |
<div class='test default required'></div> | |
<blockquote></blockquote> | |
</div> | |
<pre>div :last-child { | |
} | |
<div> | |
<div></div> | |
<blockquote></blockquote> | |
</div></pre> | |
<p> | |
The CSS selector should not match the inner div element, because it is the first child of the outer div element | |
</p> | |
</li> | |
<li> | |
<div class='defaultred'> | |
<div id='insertAfter1'></div> | |
</div> | |
<script type="text/javascript"> | |
<!-- | |
var ib = document.getElementById('insertAfter1'); | |
var el = document.createElement("div"); | |
el.className = 'test'; | |
ib.parentNode.appendChild(el); | |
//--> | |
</script> | |
<pre>div :last-child { | |
} | |
<div> | |
<div id='insertAfter'></div> | |
</div> | |
var ib = document.getElementById('insertAfter'); | |
ib.parentElement.appendChild(document.createElement("div"));</pre> | |
<p> | |
The CSS selector should match the div element that is inserted by the Javascript code. | |
</p> | |
</li> | |
<li> | |
<div class='defaultgreen'> | |
<div id='insertAfter2' class='test default'></div> | |
</div> | |
<script type="text/javascript"> | |
<!-- | |
var ib = document.getElementById('insertAfter2'); | |
ib.parentNode.appendChild(document.createElement("div")); | |
//--> | |
</script> | |
<pre>div :last-child { | |
} | |
<div> | |
<div id='insertAfter'></div> | |
</div> | |
var ib = document.getElementById('insertAfter'); | |
ib.parentElement.appendChild(document.createElement("div"));</pre> | |
<p> | |
The original div element should not be a match for the :last-child selector. | |
</p> | |
</li> | |
</ol> | |
</body> | |
</html> |