html - 在不增加宽度或列的情况下旋转表头内的图像

标签 html css html-table rotation width

通过固定表头的宽度来旋转图像。

DEMO

请看演示。列的宽度应该在 30px 左右,但不会反射(reflect)图像宽度(旋转后)要大得多。

想有一个旋转的图像并仍然保持较小的宽度(旋转图像的宽度将很容易地适应td,但无法做到这一点)

尝试了几种方法,都没有得到想要的结果。任何帮助表示赞赏。

代码

<div class="bs-example">
<table class="table">
   <thead>
     <tr>
       <th>#</th>
      <th class="rotate"><image src="http://example.com/NKV2Yt" height="20" /></th>
      <th class="rotate"><image src="http://example.com/NKV2Yt" height="20" /></th>
      <th class="rotate"><image src="http://example.com/NKV2Yt" height="20" /></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>M</td>
      <td>O</td>
      <td>@</td>
    </tr>
    <tr>
      <td>2</td>
      <td>J</td>
      <td>T</td>
      <td>@</td>
    </tr>
    <tr>
      <td>3</td>
      <td>L</td>
      <td>t</td>
      <td>@</td>
    </tr>
  </tbody>
</table>
</div><!-- /example -->

CSS ==>

th{
  height:200px;
  width:30px !important;
}
.rotate{
  -webkit-transform: rotate(-90deg);  /* Chrome, Safari 3.1+ */
 -moz-transform: rotate(-90deg);  /* Firefox 3.5-15 */
  -ms-transform: rotate(-90deg);  /* IE 9 */
   -o-transform: rotate(-90deg);  /* Opera 10.50-12.00 */
      transform: rotate(-90deg);  /* Firefox 16+, IE 10+, Opera 12.10+ */
}

最佳答案

我之前遇到过这个问题。我找到的唯一解决方案是将图像包装在另一个元素中,给该元素一个相对位置和绝对位置图像到该元素

table{
  margin: 20px 0 0 30px;}
tr,td,th{
  border: 1px solid;
}
th{
  height:100px;
  width:30px;
}
.rotate img {
  -webkit-transform: rotate(-90deg);  /* Chrome, Safari 3.1+ */
     -moz-transform: rotate(-90deg);  /* Firefox 3.5-15 */
      -ms-transform: rotate(-90deg);  /* IE 9 */
       -o-transform: rotate(-90deg);  /* Opera 10.50-12.00 */
          transform: rotate(-90deg);  /* Firefox 16+, IE 10+, Opera 12.10+ */

}

.rotate span {
  position:relative;
  width:30px;
  height:100px;
  display:block;
}

.rotate span img {
  position: absolute;
  left:-15px;
  top:50px
}

将你的图像包裹在一个 span 中

<th class="rotate"><span><image src="http://goo.gl/NKV2Yt" height="20" /></span></th>

此处更新示例 http://cssdeck.com/labs/tnbuiyv8

关于html - 在不增加宽度或列的情况下旋转表头内的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22636590/

相关文章:

html - 单击标签在 HTML 中不起作用

html - WAVE 扩展未检测到标签 + aria-labelledby

php - 用于查找 HTML 字符串中所有路径的正则表达式

html - 为什么类 ="btn btn-default"而不是只有类 ="btn-default"

html - Bootstrap Daterangepicker 样式不起作用

html - 如何在 wrapper 内获取 100% 浏览器宽度的内容

css - 如何在html中自定义单选按钮

html - 如果有打开的 `if` 标签,Razor `}` 不会注册关闭 `<table>`?

javascript - 如何在 Objective-C 中获取 HTML 表的值?

jquery - 将表格单元格放在单击上 - jquery