比   更好的选择用于显示空的 HTML 表格单元格? [英] A better alternative than   for showing empty HTML table cells?

查看:12
本文介绍了比   更好的选择用于显示空的 HTML 表格单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个经典问题 - 当您有一个空表格单元格时,浏览器不会在其周围呈现边框.还有两个众所周知的解决方法.一种是在表格单元格中放置一个 ;另一种是使用 empty-cells:show CSS 属性.

It's a classic problem - when you have an empty table cell the browser doesn't render borders around it. There are also two well-known workarounds. One is to place an   in the table cell; the other is to use the empty-cells:show CSS property.

不幸的是,两者都有缺点.  在选择文本和复制粘贴时有点难看.你会得到很多不应该有的空间,甚至可能带有异国情调的 Unicode 字符.empty-cells:show 应该正好解决这个问题,但不幸的是,它只能在从版本 8 开始的 IE 中正常工作(然后只能在符合标准的模式下).也可以通过指定 border-collapse: collapse 使其在其他版本中工作,但有时这是不希望的.就我而言,我有一个相当复杂的表格,它依赖于 border-collapse:separate 否则会造成相当混乱的 CSS/HTML 汤.

Unfortunately both have drawbacks.   is kind of ugly when it comes to selecting text and copy-pasting it. You get a lot of spaces where there shouldn't be any, perhaps even with an exotic Unicode character. empty-cells:show should address exactly this problem, but unfortunately it only works properly in IE starting with version 8 (and then only in standards-compliant mode). It can be made to work in other versions by also specifying border-collapse: collapse, but sometimes this is what is NOT desired. In my case I have a fairly complex table and it relies on border-collapse:separate and would otherwise create quite a messy CSS/HTML soup.

那么,您可能会在表格单元格中放置哪些其他内容,使 IE 绘制边框但不可见或不可复制?对于所有其他浏览器,empty-cells:show 已经可以解决问题,所以我真的只需要欺骗 IE.

So what are other things that you might put in a table cell that would make IE draw the borders yet not be visible or copyable? For all other browsers the empty-cells:show already does the trick, so I really just need to fool IE.

推荐答案

你也可以放不可见的 br 元素:

You can also put invisible br element:

<td><br style="visibility:hidden"></td>

大量不必要的代码是荒谬的,但它可以解决问题 - 没有添加额外的文本,但单元格显示.

It is ridiculous amount of unnecessary code, but it makes the trick - no additional text added yet cell is displayed.

请注意,根据官方规范 http://www.w3.org/TR/html401/struct/text.html#edef-BR.然而,它是有效的 XHTML 语法.

Note that <br/> is invalid HTML syntax according to the official specifications http://www.w3.org/TR/html401/struct/text.html#edef-BR. It is valid XHTML syntax however.

这篇关于比 &amp;nbsp; 更好的选择用于显示空的 HTML 表格单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆