skip to Main Content

I don’t want to the first two images get the custome style I wrote.

<!-- HTML -->
<div class="entry">
  <img src="image1.jpg">
  <img src="image2.jpg">
  <img src="image3.jpg">
  <img src="image4.jpg">
  <img src="image5.jpg">
</div>

I’ve just try this:

.entry img:not(:first-of-type):not(:nth-of-type(2)) {
  margin: 0 auto 20px !important;
  display: block;
  width: 350px;
  height: 250px;
}

But it’s not working
And these:

.entry img:not(:nth-child(-n+2)) {
  margin: 0 auto 20px !important;
  display: block;
  width: 350px;
  height: 250px;
}

.entry img:not(:first-child):not(:nth-child(2)) {
    margin: 0 auto 20px !important;
    display: block;
    width: 350px;
    height: 250px;
}

3

Answers


  1. Here’s how you can do it:

     .entry img:not(:nth-child(1)):not(:nth-child(2)) {
          margin: 0 auto 20px !important;
          display: block;
          width: 350px;
          height: 250px;
        }
     <div class="entry">
        <img src="image1.jpg">
        <img src="image2.jpg">
        <img src="image3.jpg">
        <img src="image4.jpg">
        <img src="image5.jpg">
     </div>
    Login or Signup to reply.
  2. Try this css selector, to select all images except the first two:

    .entry > img:not(img:nth-child(1),img:nth-child(2))
    {
       /* whatever styles you want for all img exept 1 and 2 */ 
    }
    
    Login or Signup to reply.
  3. Call first ones image and others img.

    img{} and image{} shall be different.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search