Search code examples
htmlcsscss-tables

Inside a div, how can I set a "cell spacing"?


Let's suppose there are many divs inside a div:

<div id="#container">
 div div div div
</div>

the inner divs can be next to each other even. Now I want to have 5px padding between all of then, just like cellspacing of table.


Solution

  • you would do something like:

     #container div
     {
         margin: 0px 5px 5px 0px;
     }
    

    or for only the immediate children:

     #container > div
     {
         margin: 0px 5px 5px 0px;
     }
    

    if you want the divs to go side-by-side you have to float them:

     #container div
     {
         float:left;
         clear:none;
         margin: 0px 5px 5px 0px;
     }