How to make borders collapse (on div)?

Suppose I have markup like: http://jsfiddle.net/R8eCr/ 1 /

<div class="container"> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> ... </div> 

Then css

 .container { display: table; border-collapse: collapse; } .column { float: left; overflow: hidden; width: 120px; } .cell { display: table-cell; border: 1px solid red; width: 120px; height: 20px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } 

I have an external div with display: table; border-collapse: collapse; display: table; border-collapse: collapse; and cells with display: table-cell , why aren't they still collapsing? What am I missing here?

By the way, there may be a variable number of cells in a column, so I can not only have borders on one side.

+56
css
Jul 29 '13 at 4:02
source share
6 answers

here is a demonstration

first you need to fix your syntax error,

 display: table-cell; 

not diaplay: table-cell;

  .container { display: table; border-collapse:collapse } .column { display:table-row; } .cell { display: table-cell; border: 1px solid red; width: 120px; height: 20px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } 
+25
Jul 29 '13 at 4:08
source share

Use a simple negative marker, not a mapping table.

Updated in JS Fiddle fiddle

 .container { border-style: solid; border-color: red; border-width: 1px 0 0 1px; display: inline-block; } .column { float: left; overflow: hidden; } .cell { border: 1px solid red; width: 120px; height: 20px; margin:-1px 0 0 -1px; } .clearfix { clear:both; } 
+64
Mar 25 '14 at 22:43
source share

Instead of using border use box-shadow :

  box-shadow: 2px 0 0 0 #888, 0 2px 0 0 #888, 2px 2px 0 0 #888, /* Just to fix the corner */ 2px 0 0 0 #888 inset, 0 2px 0 0 #888 inset; 

Demo: http://codepen.io/Hawkun/pen/rsIEp

+44
Mar 02 '15 at 10:40
source share

You need to use display: table-row instead of float: left; for your column and obviously how @Hushme to fix your diaplay: table-cell to display: table-cell;

  .container { display: table; border-collapse: collapse; } .column { display: table-row; overflow: hidden; width: 120px; } .cell { display: table-cell; border: 1px solid red; width: 120px; height: 20px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } 

demo

+5
Jul 29. '13 at 4:16
source share

You can also use negative fields:

 .column { float: left; overflow: hidden; width: 120px; } .cell { border: 1px solid red; width: 120px; height: 20px; box-sizing: border-box; } .cell:not(:first-child) { margin-top: -1px; } .column:not(:first-child) > .cell { margin-left: -1px; } 
 <div class="container"> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> </div> 
+2
Jan 25 '17 at 7:16
source share

Why not use an outline? this is what you want the outline: 1px solid red;

+1
Oct. 21 '16 at 4:50
source share



All Articles