Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have left and right spacing between table rows and table edge?

Tags:

html

css

sass

This is the desired effect:enter image description here

And this is what I came up with: http://jsfiddle.net/nunoarruda/3j6782js/

// table
.sw-table {
  border-collapse: separate;

  thead {
    background-color: $orange;
    color: $white;
    font-size: 15px;

    th {
      border: none !important;
      font-weight: 600;
      padding-top: 5px !important;
      padding-bottom: 5px !important;
      margin: 30px 27px !important;

      &:first-child {
        border-top-left-radius: 10px;
        padding-left: 25px;
      }

      &:last-child {
        border-top-right-radius: 10px;
      }
    }
  }

  tbody {
    color: $black;

    tr {
      td {
        border-color: $greyish;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
      }

      td:first-child {
        border-left: 1px solid $greyish;
        padding-left: 25px;
      }

      td:last-child {
        border-right: 1px solid $greyish;
      }

      &:first-child td {
        border-top: none;
      }

      &:last-child td {
        border-bottom: 1px solid $greyish;

        &:first-child {
           border-bottom-left-radius: 10px;
        }

        &:last-child {
          border-bottom-right-radius: 10px;
        }
      }
    }
  }
}

It's just missing the space between the table row and the table border. I've tried using margin, padding, border, border-collapse but I couldn't achieve the desired effect. Any ideias?

like image 396
nunoarruda Avatar asked Dec 10 '14 18:12

nunoarruda


People also ask

How do I add margins between table rows?

The space between two rows in a table can be done using CSS border-spacing and border-collapse property. The border-spacing property is used to set the spaces between cells of a table and border-collapse property is used to specify whether the border of table is collapse or not.

What do you call the space between the border and the content in a table?

HTML Table - Cell Padding. Cell padding is the space between the cell edges and the cell content.

How do you put space between table data in HTML?

The HTML <table> cellspacing Attribute is used to specify the space between the cells. The cellspacing attribute is set in terms of pixels. Attribute Values: pixels: It sets the space between the cells in terms of pixels.

How is border-spacing in a table is specified in?

The border-spacing CSS property sets the distance between the borders of adjacent cells in a <table> . This property applies only when border-collapse is separate .

Which is the correct option to provide space between the border and the wall of the page?

Margin provides the space between the border and outer elements.


1 Answers

Check this fiddle:

The most important thing I did was wrap the first and last items in divs and styled them:

<td>
  <div>Brand name</div>
</td>

This allowed me to take off the padding/border of the td and move it to the divs:

td:first-child {
  border-left: 1px solid $greyish;
  padding-left: 25px;
  padding-top: 0;
  padding-right: 0;
  border-top: none;
  div {
    border-top: 1px solid $greyish; 
    padding-top: 10px; 
    padding-right: 8px;
  }            
}

The last thing I did was remove !important on the padding because that was messing with the new code. The borders are now attached to the divs inside first and last child instead of the tds!

like image 124
austinthedeveloper Avatar answered Oct 30 '22 10:10

austinthedeveloper