html - css,带有垂直标题的表格

标签 html css html-table vertical-alignment

我正在尝试在 HTML 中构建一个标题垂直的表格。 我在那里找到了我正在寻找的东西: http://codepen.io/chriscoyier/pen/Fapif

但我无法重现它,我也不明白为什么。

我的代码是:

<html>
    <head>
        <style type="text/css">

        .table-header-rotated {
          border-collapse: collapse;
          .csstransforms & td {
             width: 30px;
          }
          .no-csstransforms & th {
             padding: 5px 10px;
          }
          td {
             text-align: center;
             padding: 10px 5px;
             border: 1px solid #ccc;
          }
          .csstransforms & th.rotate {
             height: 140px;
             white-space: nowrap;
             // Firefox needs the extra DIV for some reason, otherwise the text disappears if you rotate 
             > div {
                transform: 
                  // Magic Numbers
                  translate(25px, 51px)
                  // 45 is really 360-45
                  rotate(315deg);
                width: 30px;
             }
             > div > span {
                border-bottom: 1px solid #ccc;
                padding: 5px 10px;
             }
          }
          th.row-header {
             padding: 0 10px;
             border-bottom: 1px solid #ccc;
          }
        }

        </style>
    </head>
    <body>
<table class="table table-header-rotated">
  <thead>
    <tr>
      <!-- First column header is not rotated -->
      <th></th>
      <!-- Following headers are rotated -->
      <th class="rotate"><div><span>Column header 1</span></div></th>
        <th class="rotate"><div><span>Column header 2</span></div></th>
        <th class="rotate"><div><span>Column header 3</span></div></th>
        <th class="rotate"><div><span>Column header 4</span></div></th>
        <th class="rotate"><div><span>Column header 5</span></div></th>
        <th class="rotate"><div><span>Column header 6</span></div></th>
    </tr> 
  </thead>
  <tbody>
    <tr>
      <th class="row-header">Row header 1</th>
      <td><input checked="checked" name="column1[]" type="radio" value="row1-column1"></td>
      <td><input checked="checked" name="column2[]" type="radio" value="row1-column2"></td>
      <td><input name="column3[]" type="radio" value="row1-column3"></td>
      <td><input name="column4[]" type="radio" value="row1-column4"></td>
      <td><input name="column5[]" type="radio" value="row1-column5"></td>
      <td><input name="column6[]" type="radio" value="row1-column6"></td>
    </tr>
    <tr>
      <th class="row-header">Row header 2</th>
      <td><input name="column1[]" type="radio" value="row2-column1"></td>
      <td><input name="column2[]" type="radio" value="row2-column2"></td>
      <td><input checked="checked" name="column3[]" type="radio" value="row2-column3"></td>
      <td><input checked="checked" name="column4[]" type="radio" value="row2-column4"></td>
      <td><input name="column5[]" type="radio" value="row2-column5"></td>
      <td><input name="column6[]" type="radio" value="row2-column6"></td>
    </tr>
    <tr>
      <th class="row-header">Row header 3</th>
      <td><input name="column1[]" type="radio" value="row3-column1"></td>
      <td><input name="column2[]" type="radio" value="row3-column2"></td>
      <td><input name="column3[]" type="radio" value="row3-column3"></td>
      <td><input name="column4[]" type="radio" value="row3-column4"></td>
      <td><input checked="checked" name="column5[]" type="radio" value="row3-column5"></td>
      <td><input checked="checked" name="column6[]" type="radio" value="row3-column6"></td>
    </tr>
  </tbody>
</table>

</body>
</html>

这是一个 jsfiddle:https://jsfiddle.net/n00tevvs/

最佳答案

CSS

.table-header-rotated {
  border-collapse: collapse;
}
.table-header-rotated td {
  width: 30px;
}
 .table-header-rotated th {
  padding: 5px 10px;
}
.table-header-rotated td {
  text-align: center;
  padding: 10px 5px;
  border: 1px solid #ccc;
}
 .table-header-rotated th.rotate {
  height: 140px;
  white-space: nowrap;
}
 .table-header-rotated th.rotate > div {
  -webkit-transform: translate(25px, 51px) rotate(315deg);
      -ms-transform: translate(25px, 51px) rotate(315deg);
          transform: translate(25px, 51px) rotate(315deg);
  width: 30px;
}
 .table-header-rotated th.rotate > div > span {
  border-bottom: 1px solid #ccc;
  padding: 5px 10px;
}
.table-header-rotated th.row-header {
  padding: 0 10px;
  border-bottom: 1px solid #ccc;
}

DEMO

Check weather you have SASS code or normal CSS code.

关于html - css,带有垂直标题的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29411818/

相关文章:

html - CSS 背景图像很奇怪很奇怪我只是无法得到它

javascript - 如何使用 POST/GET 将下拉列表的值和文本发送到另一个页面

javascript - 解析 .txt 文件以使用 jQuery 填充 html 选择

javascript - 如何将html内容附加到iframe中?

javascript - css 过渡高度以隐藏容器中的内容

javascript - 表 - 固定标题,可滚动主体,最强大/最简单的解决方案?

html - H1标签没有响应

html - 如何使 div 并排显示一个固定宽度和一个屏幕的其余部分

css - 在 ajax 更新上添加 CSS 类?

html - html表格显示大量数据的设计思路