How to format tables correctly with css

I want the outer borders of my table to be broken and the inner borders to be solid. So I made these css codes for mine normal-table

, but the border of the whole tables is solid.

.zulu-post .zulu-content .normal-table{
    color: #444444;
    border: 1px dashed #444444;
}

.zulu-post .zulu-content .normal-table td, .normal-table tr{
    padding: 10px;
    border: 1px solid #444444;
}
      

<table border="1" cellpadding="1" cellspacing="1" class="normal-table" style="width:500px;">
    <tbody>
        <tr>
            <td>Table Name</td>
        </tr>
        <tr>
            <td>Make sure that Stylesheet Classes is normal-table</td>
        </tr>
        <tr>
            <td>Text Here...</td>
        </tr>
    </tbody>
</table>
      

Run codeHide result


+3


source to share


3 answers


This is one way to do what you want:

Basically you add border left and top

to all tags <td>

and then remove the border from the sides of the table and you use the dotted border on <table>

.



.normal-table {
  color: #444444;
  border: 1px dashed #444444;
}

.normal-table td {
  padding: 10px;
  border-left: 1px solid #444444;
  border-top: 1px solid #444444;
}

.normal-table td:first-child {
  border-left: none;
}

.normal-table tr:first-child td {
  border-top: none;
}
      

<table cellpadding="1" cellspacing="0" class="normal-table" style="width:500px;">
    <tbody>
        <tr>
            <td>Table Name</td>
        </tr>
        <tr>
            <td>Make sure that Stylesheet Classes is normal-table</td>
        </tr>
        <tr>
            <td>Text Here...</td>
        </tr>
    </tbody>
</table>
      

Run codeHide result


+3


source


1 use border-collpase:collapse

is the collapse

border table border

to single

, then create the style part for table, tbody, tr

, etc.



.normal-table {
  border: 2px solid red;
  border-collapse: collapse;
}

tr {
  border: 2px dashed red;
}
      

<table border="1" cellpadding="1" cellspacing="1" class="normal-table" style="width:500px;">
  <tbody>
    <tr>
      <td>Table Name</td>
    </tr>
    <tr>
      <td>Make sure that Stylesheet Classes is normal-table</td>
    </tr>
    <tr>
      <td>Text Here...</td>
    </tr>
  </tbody>
</table>
      

Run codeHide result


+1


source


You can use divs as an alternative:

.container {
  width: 100%;
  border: medium dashed darkgray;
  display: table;
}
.cell {
  width: 30%;
  border: thin solid red;
  height: 50px;
  display: table-cell;
}
      

<div class='container'>
<div class='cell'></div>
<div class='cell'></div>
<div class='cell'></div>
</div>
      

Run codeHide result


-1


source







All Articles