I have a parent div, that holds three div’s. They are basically columns. I need to remove the margin on the last one but can’t get the right selector
HTML:
<div class="productContainer">
<div class="productBox"></div>
<div class="productBox"></div>
<div class="productBox"></div>
<!--/ productContainer --></div>
Here’s the CSS:
.productContainer {
width: 980px;
height: 400px;
display: block;
float: left;
}
How do you target the third child div of a parent? this should work no?
.productContainer > .productBox {
width: 320px;
height: 400px;
display: block;
float: left;
margin: 0 10px 0 0;
}
.produtContainer > .productBox nth:child(3) {
margin-right: 0;
}
While you can use the :last-child selector, it’s not going to work in any version of IE before 8. Generally what I do in this situation is add a last class to the last element in the list:
And then add this rule below the .productContainer .productBox rule in the stylesheet: