虽然some https://stackoverflow.com/questions/2124630/forcing-a-certain-width-height-with-overflow-in-a-td 问题 https://stackoverflow.com/questions/3968561/overflow-auto-in-table-td-that-has-no-certain-height similar https://stackoverflow.com/questions/5091179/css-how-to-make-td-a-fixed-height之前已经问过这个问题,这个有点不同。
我有一张看起来有点像这样的桌子:
<table>
<tr>
<td style="height: 100px;">
<img src="..." style="height: 100px;" />
<img src="..." style="height: 100px; position: relative; top: -100px;" />
</td>
</tr>
</table>
这会将第二个图像覆盖在第一个图像上。However, the td
坚持成为200px
tall 即使只有100px
内容的。设置td
的身高没有任何作用,这似乎与其他问题的答案一致。
但是,我无法选择将内容嵌入到DIV
并将高度设置为100px
因为td
will still坚持成为200px
tall.
我怎样才能告诉td
to just be 100px
tall?
Edit:哦,使用绝对定位也是不可能的,因为页面中会进行大量 DOM 操作,并且内容会四处移动 - 而绝对定位的内容则不会。
Edit: jsFiddle http://jsfiddle.net例子可以在这里找到 http://jsfiddle.net/S3s4G/.
这与td
确实如此,但本质上position: relative
。相对元素的空间在文档流中保持保留。
摆脱relative
,并使用position: absolute
而是在第一张图片上。
Edit: I刚刚看到你的编辑。嗯。思维。
我想到了两个解决方法:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)