table高亮


最近在工作过程中,突然出现了一个好久没使用的东西了,其实主要还是关于伪元素的使用,不要小看这两个::冒号,其实他的能量其实很大的呢!!!

下面举个梨子:

html:

<main>
  <table>
    <thead>
      <tr>
        <th>th>
        <th class="col">50kgth>
        <th class="col">55kgth>
        <th class="col">60kgth>
        <th class="col">65kgth>
        <th class="col">70kgth>
      tr>
    thead>
    <tbody>
      <tr>
        <th class="row">160cmth>
        <td>20td>
        <td>21td>
        <td>23td>
        <td>25td>
        <td>27td>
      tr>

      <tr>
        <th class="row">165cmth>
        <td>18td>
        <td>20td>
        <td>22td>
        <td>24td>
        <td>26td>
      tr>

      <tr>
        <th class="row">170cmth>
        <td>17td>
        <td>19td>
        <td>21td>
        <td>23td>
        <td>25td>
      tr>

      <tr>
        <th class="row">175cmth>
        <td>16td>
        <td>18td>
        <td>20td>
        <td>22td>
        <td>24td>
      tr>
    <tbody>
  table>
main>

css:

table {
  overflow: hidden;
}

td, th {
  padding: 10px;
  position: relative;
  outline: 0;
}

body:not(.nohover) tbody tr:hover {
  background-color: #ffa;
}

td:hover::after,
thead th:not(:empty):hover::after,
td:focus::after,
thead th:not(:empty):focus::after { 
  content: '';  
  height: 10000px;
  left: 0;
  position: absolute;  
  top: -5000px;
  width: 100%;
  z-index: -1;
}

td:hover::after,
th:hover::after {
  background-color: #ffa;
}

td:focus::after,
th:focus::after {
  background-color: lightblue;
}

/* Focus stuff for mobile */
td:focus::before,
tbody th:focus::before {
  background-color: lightblue;
  content: '';  
  height: 100%;
  top: 0;
  left: -5000px;
  position: absolute;  
  width: 10000px;
  z-index: -1;
}

js:

效果:

以上