We help IT Professionals succeed at work.

Div selection is css

HelpNearMe
HelpNearMe asked
on
Hi Experts,

I'd like apply certain css properties the the fist post div in a column that sits in a word press site.

This first post will have a different width etc.  Using CSS 3 how can I identify the first div... first child I suppose.  What is the syntax?

thanks,

HNM
Comment
Watch Question

Greg AlexanderLead Developer
Commented:
Here is how I would do it

#selector:first-child
{ 
background-color:yellow;
}

Open in new window

Commented:
Could also be

#selector div.post:first-of-type

Assuming all the post divs had a class of post and #selector was the parent

first-child wouldn't work if there is another type of element that is actually the first child of the parent selector, like an <h1> tag.

Commented:
Ah, I got that wrong about first-child... it would work.   .post:first-child
Commented:
Haha... ok my first comment was correct it WONT work.

Test it here: http://www.w3schools.com/css/tryit.asp?filename=trycss_first-child3

Author

Commented:
#selector:nthchild(n) worked for me :)

thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.