This is not possible using only CSS. You mentioned that elements are dynamically generated, if so, then I programmatically put the class in the first <p> and targeted it that way.
By doing this, you will also ensure compatibility between browsers; because if possible, you would definitely need to use CSS3 pseudo-classes.
source share