user1763812
user1763812

Reputation: 437

Space between CSS Table Rows

I have a css table and am trying to make a space between each row, the gap should have no color. I have tried a few things that have not worked such as:

border-bottom: 5px solid transparent; border-top: 5px solid transparent;

and

border-collapse: collapse;

The code is below along with a jsfiddle.

Thanks.

HTML

<div class="live-mu-table" >
    <div class="live-mu-table-tr">
        <div class="live-mu-table-tdq" id="a-1">q1</div>
        <div class="live-mu-table-tdspacer1"></div>
        <div class="live-mu-table-tda" id="a-3">A3</div>
    </div>

    <div class="live-mu-table-tr">
        <div class="live-mu-table-tdq" id="q-2">q2</div>
        <div class="live-mu-table-tdspacer1"></div>
        <div class="live-mu-table-tda" id="a-1">A1</div>
    </div>

    <div class="live-mu-table-tr">
        <div class="live-mu-table-tdq" id="q-3">q3</div>
        <div class="live-mu-table-tdspacer1"></div>
        <div class="live-mu-table-tda" id="a-2">A2</div>
    </div>
</div>

CSS

.live-mu-table{
 display: table;
 background-color:Azure;
 margin-bottom: 5px;
 padding-bottom: 5px;
 position:relative;
 margin-left: auto;
 margin-right: auto;    
 width:75%;
// border-collapse: collapse;
}
.live-mu-table-tr{
    display: table-row; 
    height:30px;
}
.live-mu-table-tdq{
   display: table-cell;
  border:1px solid #000;
    width:60%;
    text-align:center;
   vertical-align:middle;   
   cursor: pointer; 
}

.live-mu-table-tda{
   display: table-cell;
    border:1px solid #000;
    width:30%;
    text-align:center;
   vertical-align:middle;
cursor: pointer;   
}

.live-mu-table-tdspacer1{
   display: table-cell;
    border:1px solid #000;
    width:10%;
    text-align:center;
   vertical-align:middle;   
}

Upvotes: 3

Views: 5652

Answers (1)

Mr Lister
Mr Lister

Reputation: 46629

Use border-spacing to create the spacing.

And if you want the gaps to have no background color, move the background-color from the table to the table-rows.

.live-mu-table {
  display: table;
  margin-bottom: 5px;
  padding-bottom: 5px;
  position: relative;
  margin-left: auto;
  margin-right: auto;
  width: 75%;
  border-spacing: 0 3px;     /* new */
}
.live-mu-table-tr {
  display: table-row;
  height: 30px;
  background-color: Azure;   /* moved */
}
.live-mu-table-tdq {
  display: table-cell;
  border: 1px solid #000;
  width: 60%;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
}
.live-mu-table-tda {
  display: table-cell;
  border: 1px solid #000;
  width: 30%;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
}
.live-mu-table-tdspacer1 {
  display: table-cell;
  border: 1px solid #000;
  width: 10%;
  text-align: center;
  vertical-align: middle;
}
<div class="live-mu-table">
  <div class="live-mu-table-tr">
    <div class="live-mu-table-tdq" id="a-1">q1</div>
    <div class="live-mu-table-tdspacer1"></div>
    <div class="live-mu-table-tda" id="a-3">A3</div>
  </div>

  <div class="live-mu-table-tr">
    <div class="live-mu-table-tdq" id="q-2">q2</div>
    <div class="live-mu-table-tdspacer1"></div>
    <div class="live-mu-table-tda" id="a-1-2">A1</div>
  </div>

  <div class="live-mu-table-tr">
    <div class="live-mu-table-tdq" id="q-3">q3</div>
    <div class="live-mu-table-tdspacer1"></div>
    <div class="live-mu-table-tda" id="a-2">A2</div>
  </div>
</div>

Upvotes: 4

Related Questions