Yea, that's good. But I have some <span> before my <p>, so that method doesn't worked there. Here is my code:
<style> .post p:first-child{ Some custom classes for my first <p> tag. } </style>
<body> <div class="post"> <span>Some texts is in it</span> <p><img src="" alt=""></p> <!-- I want to give this <p> a different class --> <p><img src="" alt=""></p> </div></body>
:first-child grabs the first of the selected element, not the first thing inside of it. so p:first-child grabs the first 'p', not the first thing inside it
I tried that, but doesn't worked. See Here. I want to give that style to the first image in the .home-post-wrap DIV. I put that code in my style-Red.css and nothing changed. What's wrong?
@Mottie, Yea, I tried the first solution and that worked, but as you said, that may change in some posts, for example when I put a video at the first of my post. I used jQuery solution and that worked great, Thanks!
@cnwtx, I haven't <p> tag around my images, so I changed that code to img:first-of-type and that worked in most of my posts, but in some of them I saw <p> tag around my images and there the solution doesn't worked.
I tried img:first-of-type, p:first-of-type, that give the first image, first <p> tag and the first images in <p> tags, a different class. I used that jQuery method and that work great. It is good to use a pure CSS method, but if not, there is no problem.
I want to make the first picture of my post a different style.
<span>before my<p>, so that method doesn't worked there. Here is my code::first-child grabs the first of the selected element, not the first thing inside of it. so p:first-child grabs the first 'p', not the first thing inside it
<p>tags from around images, now what method I should use?.post img:first-child{}doesn't worked..home-post-wrapDIV. I put that code in my style-Red.css and nothing changed. What's wrong?not sure about IE9IE9 supports it.I used jQuery solution and that worked great, Thanks!
@cnwtx, I haven't
<p>tag around my images, so I changed that code toimg:first-of-typeand that worked in most of my posts, but in some of them I saw<p>tag around my images and there the solution doesn't worked.@noahgelman, Thank you so much for the helps.
:nth-of-type(n):nth-last-of-type(n)and:last-of-typeselectors.@farzadina what about this:
img:first-of-type, p:first-of-type?img:first-of-type, p:first-of-type, that give the first image, first<p>tag and the first images in<p>tags, a different class.I used that jQuery method and that work great. It is good to use a pure CSS method, but if not, there is no problem.