CSS last child of a row

10,778

You could apply nth-child for your first solution

.testbox:nth-child(3n) {
    background: blue;
}

An example: http://jsfiddle.net/uq9zaav3/3/

For the second solution you have to declare when and where you want to use a clear div so it could also be done with nth-child(..).

Share:
10,778
xQp
Author by

xQp

Updated on June 04, 2022

Comments

  • xQp
    xQp almost 2 years

    I am creating DIVs from a MySQL Query with a CSS float: left; style
    all of them have a width of 300px and the wrapping container is set to 900px.

    So after every 3rd Box, there is a new line.
    but there is also the possibility to set a <div class="clear"></div> after the first or second DIV

    Is it possible to remove right boarder from the last-child of a row?
    or maybe after the clear-Div?

    http://jsfiddle.net/uq9zaav3/2/
    example with background color, but it should be no problem to make it with border ;)

  • xQp
    xQp over 9 years
    yep thats the solution i knew, but i hoped there was another :/ - is there no posibility to change color of a div if its followed by another div class or by a specific div class?
  • Hashem Qolami
    Hashem Qolami over 9 years
    @xQp There's no backward selector in CSS, therefore the answer is No.
  • Vangel Tzo
    Vangel Tzo over 9 years
    As @HashemQolami said you can't go backward you could only trigger the next element of a div with class clear. But you can always add a class which will remove the margin directly to the last element of it's row. Not an elegant solution although
  • xQp
    xQp over 9 years
    that makes no sense doing it with jquery, ill get every 3rd yellow with that code without java/jquery by just using CSS3 and as i said my problem is that i need a rule for 'last child of a row' which is not working so i need to find another soluten but thx ;)