如何在单行上显示表格的行 () (Internet Explorer 6,7)?
我想在一行上显示表格的行。这是 Internet Explorer 6 和 7 中的一个问题,因为将 float 属性设置为 left 并将显示设置为 block 是行不通的。将 更改为
也不起作用,因为这些 html 元素是由我不允许更改的框架代码生成的。
编辑:你们中的一些人想要代码,我不知道为什么它会有所帮助,但它就在这里(特定图像和类已被编辑掉,代码在网上不可用,一些类< /em> 可能不是所有地方都是同一个类)
<table class="some-class" width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr class="some-class">
<td class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<div class="some-class">
<div class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<p></p>
<p></p>
</div> <a href="#"><img src=pic.jpg"/></a>
</div>
</td>
</tr>
<tr class="some-class">
<td class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<div class="some-class">
<div class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<p></p>
<p></p>
</div> <a href="#"><img src=pic.jpg"/></a>
</div>
</td>
</tr>
<tr class="some-class">
<td class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<div class="some-class">
<div class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<p></p>
<p></p>
</div> <a href="#"><img src=pic.jpg"/></a>
</div>
</td>
</tr>
</table>
I want to display the rows of a table on a single line. This is a problem in Internet Explorer 6 and 7 because setting the float attribute to left and the display to block won't do. And changing <tr>
s to <td>
s won't do either as these html elements are generated by a framework's code that i am not allowed to change.
Edit: Some of you wanted the code, i dunno why it would help but here it is (specific images and classes have been edited out, the code is not available online, some-class may not be the same class everywhere)
<table class="some-class" width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr class="some-class">
<td class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<div class="some-class">
<div class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<p></p>
<p></p>
</div> <a href="#"><img src=pic.jpg"/></a>
</div>
</td>
</tr>
<tr class="some-class">
<td class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<div class="some-class">
<div class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<p></p>
<p></p>
</div> <a href="#"><img src=pic.jpg"/></a>
</div>
</td>
</tr>
<tr class="some-class">
<td class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<div class="some-class">
<div class="some-class">
<a href="#"><img src=pic.jpg"/></a>
<p></p>
<p></p>
</div> <a href="#"><img src=pic.jpg"/></a>
</div>
</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
恐怕我认为这无法以理智且有效的方式完成。编辑: 这似乎是有效的(!)并且可以通过去掉每个元素的float: left
在表格中绝对是禁忌。table- *
显示属性,但 IE 不太支持。我能想到的唯一可行的解决方案是使用 JavaScript/jQuery 操作表格元素,并进行所需的转换(
tr
s 到td
s...)。其明显的缺点是它无法在 JavaScript 关闭的情况下工作。
I'm afraid I don't think this can be done in a sane and valid manner.Edit: This seems to be valid (!) and possible by taking away each element'sfloat: left
in a table is absolutely taboo.table-*
display property, but isn't well supported by IE.The only workable solution I can think of is manipulating the table elements using JavaScript/jQuery, and making the needed conversions (
tr
s intotd
s...).The obvious downside of that is that it won't work with JavaScript turned off.
您是否考虑过使用 Javascript 和/或 Javascript 库(如 JQuery)在客户端上重新格式化?例如,应该可以操纵 DOM 创建适当的显示结构,可能用 DIV 替换表格元素。
Have you thought about reformatting on the client using Javascript and/or a Javascript library like JQuery? It should be possible to manipulate the DOM to create an appropriate display structure possibly replacing the table elements with DIVs, for example.
好吧,有一个 css 解决方案并非没有缺点,所以我不能说我全心全意地推荐它(并且尚未经过跨浏览器的彻底测试),但出于“可能性”的目的,我提供它:
稍微修改一下您的 html 进行说明(在
tr
标记中添加了一些类):在查看 css 之前需要注意的一些事项:
display: block
对于 FireFox 中用于显示目的的某些表格元素,IE6-7 将忽略这些元素。如果您认为该解决方案适合您的目的,您可能只想将此解决方案定位于 IE6-7。td
元素使用设置和等宽度,并且仅对 3 行有效。数字必须根据要在行中显示的行数进行更改。基本上,我的观点是,这可能不适用于您的情况,但它至少说明了在适当的情况下,可以仅使用 css 来完成您所要求的操作。css:
理想情况下,行具有设定的高度,因为
table
最终以height:0
结束,因为其中的数据是position:absolute,因此如果可能的话,建议为
table
设置一个高度
。Well, there is a css solution that is not without it's drawbacks, so I cannot say I whole-heartedly recommend it (and has not been thoroughly tested cross browser), but for purposes of "possibility" I offer it:
A slight modification of your html for illustration (added some classes to the
tr
tags):Some things to note before looking at the css:
display: block
to some of the table elements for display purposes in FireFox, IE6-7 will ignore those. You may want to just target this solution to IE6-7 if you decide that it fits your purposes.td
elements and is only valid for 3 rows. Numbers would have to change based on # of rows to display in line. Basically, my point is, this may not work for your situation, but it at least illustrative that given the right circumstances, it is possible to do what you requested with css only.The css:
This would ideally have rows with set heights, as the
table
ends up with aheight: 0
since the data within it isposition: absolute
, so setting aheight
to thetable
would be recommended if possible.