【问题标题】:Firefox + Chrome table rendering issueFirefox + Chrome 表格渲染问题
【发布时间】:2013-05-24 19:45:43
【问题描述】:

我在显示以编程方式显示列的表格时遇到问题。

以下是可以看到此问题的 html 代码(并已确认其不是影响渲染的代码)。

<table>
<tr>
    <th>NUMER</th>                                      
    <th>NAME</th>
    <th align="center" style="display:block;">LOCATION</th>
    <th align="center" style="display:none;">1</th>
    <th align="center" style="display:block;">2</th>
</tr>
<tr>
    <td>12345</td>
    <td>BOB Jr</td>                                     
    <td align="center" style="display:block;"><input type="CheckBox" ID="updateLocation" runat="server" /></td>
    <td align="center" style="display:none;"><input type="CheckBox" ID="updateLocation" runat="server" /></td>
    <td align="center" style="display:block;"><input type="CheckBox" ID="updateLocation" runat="server" /></td>                                            
</tr>

这将在 Chrome 和 Firefox 上显示如下:

样式是以编程方式添加的,这显然是导致问题的原因,但是我想知道是否有人有解决此问题的建议?

表格列必须以编程方式显示,因为此功能是用户驱动的。

另请注意,这在 IE 上运行良好。

【问题讨论】:

  • 不确定是什么吸引了反对票,对我来说似乎是一个非常好的问题?

标签: c# javascript asp.net css firefox


【解决方案1】:

不要使用

 display:block

这与表格不兼容。

您正在寻找:

display:table-cell

也就是说,我建议您在继续之前先仔细阅读这个问题并回答,尤其是如果您必须支持旧版 IE:show/hide html table columns using css

【讨论】:

  • 谢谢,这对我很有帮助,因为我没想到要使用这个 css 属性。就我在IE8上测试过的浏览器而言,这个功能正常,我不会支持任何旧浏览器。
【解决方案2】:

您看到此问题是由于您的 HTML 代码中的一种非常特殊的样式。从 html 中删除 style="display:block" (或以编程方式插入)将解决该问题。参考修正后的 HTML 标记。

<table>
<tbody>
    <tr>
        <th>NUMER</th>                                      
        <th>NAME</th>
        <th align="center" style="">LOCATION</th>
        <th align="center" style="display:none;">1</th>
        <th align="center" style="">2</th>
    </tr>
    <tr>
            <td>12345</td>
            <td>BOB Jr</td>                                     
            <td align="center" style=""><input type="CheckBox" id="updateLocation" runat="server"></td>
            <td align="center" style="display:none;"><input type="CheckBox" id="updateLocation" runat="server"></td>
            <td align="center" style=""><input type="CheckBox" id="updateLocation" runat="server"></td>                                            
    </tr>
</tbody>

希望这会有所帮助。

【讨论】:

  • 嗨,Praneeth,这是一个很好的解决方案,但感觉太老套了,但我尝试的是 @KingCronus 所说的使用 display:table-cell。这解决了这个问题,因为我仍然可以继续使用 css 来显示列,这是我以编程方式传递的内容,传递一个空字符串感觉不对。
猜你喜欢
  • 2014-05-03
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
  • 2012-10-03
  • 2020-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多