Well this can be explained on basis of Electrostatic Potential energy(U)
In a system of unlike charges +q and -q
U_1=k \frac{-q^2}{r^2}  
where r is the distance between point charges 
In a system of like charges +q and +q or -q and -q
U_2=k \frac{q^2}{r^2}  
where r is the distance between point charges 
so charges are more stable at less energy
so a charge has less energy when it is close to another opposite charge
more the closer it is lesser the energy so opposite charges attract each other
 When a charge is close to another like charge it is at high energy so they repel
as distance between them increases energy between them decreases
Charge has less energy when close to another opposite charge when charges are more closer lesser their opposite charge attract each other.
when charge close to another like charge there is increase in energy repel each other
as distance increase and energy decrease........hope this will help u!!!!!!!!!!!!!