为什么colgroup / col在Chrome中不起作用 [英] Why colgroup/col doesn't work in Chrome

查看:328
本文介绍了为什么colgroup / col在Chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上一个问题的答案之一声明colgroup / col只能在IE中工作。

One of the answers to my previous question states that colgroup/col should work in IE only.

我写了一个例子(见下文)第3栏),但不适用于最新版本的Chrome。

I've wrote an example (see below) that works on IE9 (centers cells content in the the 3rd column), but doesn't work on the latest version of Chrome.

我做错了什么?

HTML示例:

<html>
<head><title>test table centerring</title></head>
<body>

    <table border="1">
        <colgroup>
            <col/>
            <col/>
            <col align="center">
        </colgroup>
        <thead>
            <tr>
                <th>#</th>
                <th>Name</th>
                <th>Value</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>Name 1</td>
                <td>Value 1</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Name 2, Name 2, Name 2, Name 2</td>
                <td>Value 2</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Name 3</td>
                <td>Value 3</td>
            </tr>
            <tr>
                <td>4</td>
                <td>Name 4</td>
                <td>Value 4, Value 4, Value 4, Value 4</td>
            </tr>
        </tbody>
    </table>        

</body></html>


推荐答案

实际上,我确定只有IE支持,但被问题的答案之一困惑了是有什么方法可以将表格中的特定列置中?。作者的回答也指出了一些限制:
http://www.quirksmode.org /css/columns.html

Actually, I was pretty sure that only IE supports that, but was confused by one of the answers to question Is there any way to center certain columns in table?. The author of answer pointed also to some restrictions: http://www.quirksmode.org/css/columns.html


不幸的是,表列很难使用,因为如果使用它们,表格按两种方式进行细分:按行和按列。一般规则是,在行上定义的任何样式都会覆盖在列上定义的任何样式。

Unfortunately table columns are quite hard to use, because if you use them you essentially have a table that's subdivided in two ways: by rows and by columns. The general rule is that any style defined on a row overrules any style defined on a column.

其次,W3C指定在列上只能使用几个声明:border ,背景,宽度和可见性。例外:IE7和更低版本允许所有声明。

Secondly, W3C specifies that only a few declarations may be used on columns: border, background, width and visibility. Exception: IE7 and lower allow all declarations.

第三,有一些混乱,无论列样式是作为整体应用于列还是应用于个人< td> 。边界声明似乎应用于整个列,但宽度应用于单个单元格。

Thirdly, there's some confusion whether the column styles are applied to the column as a whole, or to the individual <td>s contained by it. The border declaration seems to be applied to the column as a whole, but width is applied to the individual cells.

col几乎不能用于居中。

That made colgroup/col pretty much useless for centering.

这篇关于为什么colgroup / col在Chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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