I've been struggling with finding a way to only display the first child of my div and hide all the rest. Can this be done purely in css or do I have to involve some Javascript?
So, how can I get this to only display first p-tag?
<div id="test1">
<p>Lorem ipsum</p>
<p>Lorem ipsum</p>
<p>Lorem ipsum</p>
</div>
http://jsfiddle.net/8XYNx/
A combination of :not
and first-child
should surely do it:
#test1 p:not(:first-child) {
display: none;
}
Note that this won't work in IE before version 9.
try this
http://jsfiddle.net/8XYNx/10/
CSS
#test1 p{
display:none;
}
#test1 p:first-child{
display:block;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With