1

I want to align 3 divs, next to each other. so I used display:table to the parent div and display:table-cell to the inner 3 divs.

Width of first 2 div is known and width of 3rd div is unknown. So the use of display:table-cell works perfectly for me to adjust the width of 3rd div.

Now if I want to give spacing between 3 divs using margin-left or margin-right, then there is no effect. Please check code here.

Let me know if we can do that. Thanks in advance.

Ashwin
  • 12,081
  • 22
  • 83
  • 117

4 Answers4

1

This should work:

 #wrapper div {
      display: table-cell;
      height:100px;
      /* creates space */
      border:5px solid transparent;
      background-clip:padding-box;
  }

You might want to set a different box-modell to include the border in the width of the elements via:

box-sizing:border-box;
Christoph
  • 50,121
  • 21
  • 99
  • 128
0

Use border property to give space like

border:solid 10px transparent;
0

Try this

#wrapper {
    display: table;
    table-layout: fixed;
    width:100%;
    height:100px;
    background-color:Gray;
    border-spacing:10px;
}

DEMO.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

Table cells cannot have margins. You can tweak it a bit by using transparent borders and if that doesn't solve your problem then there's no other way.

Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133