Runerbex
Runerbex

Reputation: 33

Ruby Table CSS - Background is not working properly

I would like to fit the grey background properly without those leaps.

This is an example:

table {
  font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  //background-color: #5CAF50;
  font-weight: bold;
  padding-left: 5px;
}

td {
  padding-left: 5px;
}

tr:nth-child(odd) {
  background-color: #F8F8F8;
}
<table>
  <tr>
    <th>Verb</th>
    <td><ruby>来<rt>く</rt>る</ruby></td>
  </tr>
  <tr>
    <th>Verb</th>
    <td><ruby>食<rt>た</rt>べる</ruby></td>
  </tr>
  <tr>
    <th>Verb</th>
    <td><ruby>行<rt>い</rt>く</ruby></td>
  </tr>
</table>

enter image description here

Upvotes: 1

Views: 36

Answers (1)

Temani Afif
Temani Afif

Reputation: 272947

I am not really sure about the issue but one way is to consider a pseudo element to simulate the background layer:

table {
  font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
  overflow:hidden;
}

th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  font-weight: bold;
  padding-left: 5px;
  position:relative;
  z-index:0;
}

td {
  padding-left: 5px;
  position:relative;
  z-index:0;
}


tr:nth-child(odd) th::before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  bottom:0;
  left:0;
  width:100vw;
  background-color: #F8F8F8;
}
<table>
  <tr>
    <th>Verb</th>
    <td><ruby>来<rt>く</rt>る</ruby></td>
  </tr>
  <tr>
    <th>Verb</th>
    <td><ruby>食<rt>た</rt>べる</ruby></td>
  </tr>
  <tr>
    <th>Verb</th>
    <td><ruby>行<rt>い</rt>く</ruby></td>
  </tr>
</table>

Upvotes: 1

Related Questions