Sunday 8 December 2019

css - How to style only the first instance of this div



I am trying to apply a style to every instance of a div except the first, I've tried every combination of nth-child and first-of-type that I can think of to no avail.



Here is the HTML:




 


April



18FRI


Test Event


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam bibendum ut sem sed sagittis.


RSVP








20SUN


Test Event 2


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam bibendum ut sem sed sagittis.


RSVP








 




I would like to apply a style to every instance of the "description" div EXCEPT for the first instance, can anyone tell me what selector I would use for this? Thanks!



Answer



Doing this with CSS natively is currently not possible: see this question.






However, one way to do this is to apply the styles using jQuery:



$($(".description")[0]).css({

background: "red",

width: "40%"

});







You could also create a CSS class with the changes and apply that to the first element using jQuery:




$($(".description")[0]).addClass("first-description");



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...