【问题标题】:How to vertically stretch span to its parent element <td> with css in IE11如何在 IE11 中使用 css 将跨度垂直拉伸到其父元素 <td>
【发布时间】:2017-04-28 08:28:10
【问题描述】:

我有一个包含 span 元素的表。我需要将这些 span 元素拉伸到 span 元素所在的表格单元格的整个宽度和高度。

我可以轻松地将跨度水平拉伸到 100%,但我没有那么幸运垂直拉伸跨度。我已经花了几个小时尝试以下 css 属性及其各种值的不同组合......“显示”、“溢出”和“位置”等。到目前为止还没有运气。

任何关于如何将跨度拉伸到父元素的 100% 高度的提示将不胜感激。

这是我的代码示例:

.testTable tbody>tr>td {
  vertical-align: top;
}

.customSpan {
  border: 1px solid green;
  margin: 0 auto;
  padding: 0px;
  display: table;
  background: orange;
  width: 100%;
  height: 100%;
}
<table border=1 width=500px class="testTable">
  <thead>
    <tr>
      <th>head123</th>
      <th>head123</th>
      <th>head123</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="customSpan">test 123</span></td>
      <td><span class="customSpan">test 123</span></td>
      <td><span class="customSpan">test 123 test 123</span></td>
    </tr>
    <tr>
      <td><span class="customSpan">test 123 test 123 test 123 test </span></td>
      <td><span class="customSpan">test 123 test 123 test 123 test January test 123 test 123 test 123 test 123 test 123 test</span></td>
      <td rowspan="2"><span class="customSpan">test 123/span></td>
			  </tr>
			  <tr>
				<td><span class="customSpan">test 123</span></td>
      <td><span class="customSpan">test 123 test 123 test 123</span></td>
    </tr>
  </tbody>
</table>

这是我想要完成的工作的直观表示。

谢谢!

【问题讨论】:

  • 如果你想给td的背景上色你可以直接把class放在td上吗?您不必担心跨度的样式。我的跨度是做什么用的?

标签: javascript html css internet-explorer-11


【解决方案1】:

你需要给 td 添加一个高度值,像这样:

.testTable td{
  height:100%;
}

这里有一个有趣的帖子:https://stackoverflow.com/a/19703263/7920525

【讨论】:

  • 感谢您的回复。不幸的是,通常情况下,此解决方案适用于 Chrome 和 FF,但似乎不适用于 Edge (v40) 或 IE11。我主要关注的浏览器是 IE 和 Edge。
  • 如果你添加一个特定的高度值,这行得通吗?喜欢height: 100px;。它看起来在指定的 Edge 上对我有用。
  • 哈!是的,它似乎工作...... .testTable tbody >tr >td{ vertical-align: top;高度:1px;即使我将高度设置为只有 1px。我很困惑,但我似乎做到了。非常感谢@webbm!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-24
  • 2013-04-24
相关资源
最近更新 更多