css equivalent of first:child to target first <p> in div with heading and img preceding?
The most straightforward way to do it is to use CSS3's :first-of-type
:
#feature > p:first-of-type {
font-size: 22px;
}
But browser support for it is poor, so for your case you can try using this CSS2-only selector, assuming the first p
is always followed by an h2
and an img
(from your question title):
#feature > h2:first-child + img + p {
font-size: 22px;
}
you can target the element above the p, then use "+" adjacent selector to select the p.
so in your case would be:
#feature img + p {
font-size: 22px;
}
and it supports from IE7
Check this working code on Fiddle