Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove left and right margin on first and last div

Tags:

css

I have more than 100 divs on the page and each row has 3 divs. I want to remove left margin from first div and right margin from right div whereas center div should have 15px margin from left and right. Please guide me how can I do that without giving specific classes (no margin) on each div. Here is the example

enter image description here here is my css code

.prp_box{
    margin:15px 15px;
    width:100px;
    height:100px;
    background:#5f03a6;
    }
like image 781
Awais Imran Avatar asked Aug 02 '13 03:08

Awais Imran


2 Answers

Check this out : http://jsfiddle.net/VHXEp/

Use nth-child(n) CSS3 selector.

like image 115
Sasidhar Vanga Avatar answered Nov 09 '22 20:11

Sasidhar Vanga


You could try using the nth-child css selector.

#container:nth-child(3n+0)
{
margin-left: 0;
}
#container:nth-child(3n+3)
{
margin-right: 0;
}

This code might need a few adjustments, the 3n is how often, so every 3. The number after the + is where to start

like image 24
rjf0909 Avatar answered Nov 09 '22 18:11

rjf0909