How can I properly rotate a text inside a table cell

前端 未结 1 1687
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 06:16

I tried to create a classic HTML table with a title top and left. Now I want to rotate the text in the left title by -90°.

Css only supports 90° wit

相关标签:
1条回答
  • 2021-01-19 06:50

    You can use writing-mode: vertical-rl; combined with a scale transformation:

    table {
      text-align: left;
      border-collapse: collapse;
    }
    
    td,
    th {
      border: 1px solid lightgrey;
      padding: 0px 3px;
    }
    
    td:not(:first-child) {
      min-width: 140px;
    }
    
    .table_title_top {
      text-align: center;
    }
    
    .table_title_left {
      text-align: center;
      width: 35px;
    }
    
    .table_title_left div {
       writing-mode: vertical-rl;
       white-space:nowrap;
       transform:scale(-1);
    }
    <!DOCTYPE html>
    <html lang="en" dir="ltr">
    
    <head>
      <meta charset="utf-8">
    </head>
    
    <body>
      <table>
        <tbody>
          <tr>
            <td></td>
            <td colspan="100" class="table_title_top">
              <div>Title Top Title Top</div>
            </td>
          </tr>
          <tr class="calc-tr calc-tr-title">
            <td rowspan="100" class="table_title_left">
              <div>Title Left Title Left</div>
            </td>
            <td>0</td>
            <td>0</td>
            <td>0</td>
          </tr>
          <tr>
            <td>0</td>
            <td>0</td>
            <td>0</td>
          </tr>
          <tr>
            <td>0</td>
            <td>0</td>
            <td>0</td>
          </tr>
        </tbody>
      </table>
    </body>
    
    </html>

    0 讨论(0)
提交回复
热议问题