我怎样才能模拟“”?与CSS?

发布于 2024-11-05 02:34:59 字数 633 浏览 0 评论 0原文

我正在使用 ExtJS 编写一个 Web 应用程序。我将一个表放入一个表中,由于各种原因,不可能将其全部重构为具有行跨度/列跨度等的一个大表。

“外部”表的单元格周围有边框。我希望我的“内部”表格的单元格之间有边框,这样我最终会得到“拆分”现有(“外部”)单元格的效果。

如果它让事情变得更清楚,这就是我正在拍摄的,作为(可怜的)ascii 艺术:(

-----------------
|               |
|     |   |     |
|  -----------  |
|     |   |     |
|  -----------  |
|     |   |     |
|               |
-----------------

“内部”表格看起来像井字游戏网格;“外部”表格的单元格具有不间断的边框)

我环顾四周,发现了一个名为 RULES属性,听起来它就是这样做的。然而,它似乎没有得到很好的支持,而且无论如何我不应该在标记中添加样式(对吗?)。我找到的文档说“使用 CSS 代替”,但我似乎找不到一种简单的方法来表示“在单元格之间放置边框,但如果单元格的边缘接触表格的外部则不会” 。帮助?

I'm writing a web application using ExtJS. I'm putting a table inside a table, and for various reasons it's impossible to refactor it all into one big table with rowspan/colspan, etc.

The "outside" table has borders around its cells. I'd like my "inside" table to have borders between its cells, so that I wind up with the effect of "splitting" the existing ("outside") cell.

If it makes things clearer, this is what I'm shooting for, as (poor) ascii art:

-----------------
|               |
|     |   |     |
|  -----------  |
|     |   |     |
|  -----------  |
|     |   |     |
|               |
-----------------

(The "inner" table looks like a tic-tac-toe grid; the "outer" table's cell has an unbroken border)

I looked around, and found a <table> attribute called RULES, which sounds like it does just this. However, it seems to be poorly supported, and anyway I'm not supposed to put style in markup (right?). The documentation I've found says "use CSS instead", but I can't seem to find a simple way of saying "put a border between cells, but not if the edge of the cell touches the outside of the table" in CSS. Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

度的依靠╰つ 2024-11-12 02:34:59

这个 http://codepen.io/morewry/pen/GnBFu 是我能想到的最接近的得到。我怀疑会存在一些支持问题,并且单元格的对齐会因边框间距的量而偏离。

table{
    table-layout:fixed;
    border-collapse:separate;
    border-spacing:0.25em;
    border:1px solid red;
}
    tr{
        display:block;
        border-bottom:1px dashed blue;
    }
    tr:last-child{ border:0; }
        td{
            padding-right:0.25em;
            vertical-align:top;
            border:1px dotted orange;
            border-width:0 1px;
        }
        td:first-child,
        td + td{ border-left:0; }
        td:last-child{ padding-right:0; border-right:0; }

编辑

重新阅读后,我意识到您并不是在单个表格中寻找分隔的边框,而只是为了抑制嵌套表格上单元格之间的边框以外的边框。这要简单得多http://codepen.io/morewry/pen/yxvGg

table{
    table-layout:fixed;
    border-collapse:collapse;
    border-spacing:0;
    border-style:hidden;
}
    td{
        padding:0.25em;
        border:1px solid black;
    }

边界冲突解决状态border-style:hidden 优先,因此折叠模型中出现的唯一内容位于单元格之间。

这里唯一的问题是 IE 不支持隐藏,因此对于 IE 您需要解决方法。伪类应该适用于 IE8。我认为 IE7 不支持 :last-child,因此它需要一些额外的帮助,而 IE6 则需要针对 :first-child 和 :last-child 的解决方法。

对于 IE8 和 IE7,以下内容将模拟 border:hidden

table{ border:2px solid transparent; }

您将在这些浏览器中获得 2 个额外像素的透明空间,但效率更高。我记得 IE6 并不能正确支持透明边框,它仍然会有问题。请参阅http://codepen.io/morewry/pen/bIvJa

This http://codepen.io/morewry/pen/GnBFu is about as close as I can get. I suspect there will be some support issues and the alignment of the cells is off by the amount of the border-spacing.

table{
    table-layout:fixed;
    border-collapse:separate;
    border-spacing:0.25em;
    border:1px solid red;
}
    tr{
        display:block;
        border-bottom:1px dashed blue;
    }
    tr:last-child{ border:0; }
        td{
            padding-right:0.25em;
            vertical-align:top;
            border:1px dotted orange;
            border-width:0 1px;
        }
        td:first-child,
        td + td{ border-left:0; }
        td:last-child{ padding-right:0; border-right:0; }

Edit

Upon re-reading I realized you weren't looking for separated borders in a single table, but only to suppress the borders except between cells on a nested table. That's much simpler http://codepen.io/morewry/pen/yxvGg:

table{
    table-layout:fixed;
    border-collapse:collapse;
    border-spacing:0;
    border-style:hidden;
}
    td{
        padding:0.25em;
        border:1px solid black;
    }

Border conflict resolution states that the border-style:hidden takes precedence, so the only ones that appear in the collapsed model are between the cells.

The only issue here is that IE doesn't support hidden, so for IE you'd need workarounds. The pseudo-classes ought to work for IE8. I don't think IE7 supported :last-child, so it would need some extra help, and IE6 would need a workaround for both :first-child and :last-child.

For IE8 and IE7, the following will simulate border:hidden

table{ border:2px solid transparent; }

You'd get 2 extra pixels of transparent space in those browsers, but it's more efficient. IE6, as I recall, doesn't properly support transparent borders, it would still have issues. See http://codepen.io/morewry/pen/bIvJa.

单身狗的梦 2024-11-12 02:34:59

您可以提升 Mozilla 的 rules 属性实现,该属性完全采用 CSS:

http://hg.mozilla.org/mozilla-central/file/3fd770ef6a65/layout/style/html.css#l289
http://hg.mozilla.org/mozilla -central/file/3fd770ef6a65/layout/style/html.css#l337 是样式,从第 410 行开始。

You could lift Mozilla's implementation of the rules attribute, which is entirely in CSS:

http://hg.mozilla.org/mozilla-central/file/3fd770ef6a65/layout/style/html.css#l289 and
http://hg.mozilla.org/mozilla-central/file/3fd770ef6a65/layout/style/html.css#l337 are the styles, going on through line 410.

木落 2024-11-12 02:34:59

简单示例http://jsfiddle.net/xixionia/v3eVq/

简单表格(尽管没有tbody):

<table>
    <tr>
        <td>00</td>
        <td>01</td>
        <td>02</td>
    </tr>
    <tr>
        <td>10</td>
        <td>11</td>
        <td>12</td>
    </tr>
    <tr>
        <td>20</td>
        <td>21</td>
        <td>22</td>
    </tr>
</table>

简单CSS(尽管不完全兼容所有浏览器):

/* outline */
table
{
    border: 2px solid red;
}

/* rows */
tr
{
    border-top: 2px solid black;
    border-bottom: 2px solid black;
}

/* columns */
td
{
    padding: 10px;
    border-left: 2px solid black;
    border-right: 2px solid black;
}

/* resets */
tr:first-child
{
    border-top: none;
}

tr:last-child
{
    border-bottom: none;
}

td:first-child
{
    border-left: none;
}

td:last-child
{
    border-right: none;
}

伪选择器参考关于 W3 学校http://www.w3schools.com/css/css_pseudo_classes.asp

不使用伪选择器

您可以为每个第一个子级和最后一个子级设置一个类,并使用该类作为选择器。

Simple Example: http://jsfiddle.net/xixionia/v3eVq/

Simple Table (albiet without tbody):

<table>
    <tr>
        <td>00</td>
        <td>01</td>
        <td>02</td>
    </tr>
    <tr>
        <td>10</td>
        <td>11</td>
        <td>12</td>
    </tr>
    <tr>
        <td>20</td>
        <td>21</td>
        <td>22</td>
    </tr>
</table>

Simple CSS (albiet not completely compatible with all browsers):

/* outline */
table
{
    border: 2px solid red;
}

/* rows */
tr
{
    border-top: 2px solid black;
    border-bottom: 2px solid black;
}

/* columns */
td
{
    padding: 10px;
    border-left: 2px solid black;
    border-right: 2px solid black;
}

/* resets */
tr:first-child
{
    border-top: none;
}

tr:last-child
{
    border-bottom: none;
}

td:first-child
{
    border-left: none;
}

td:last-child
{
    border-right: none;
}

Psuedo-selector reference on W3 Schools: http://www.w3schools.com/css/css_pseudo_classes.asp

Instead of using psuedo-selectors:

You can set a class for each first-child and last-child, and use that class as your selector.

荒人说梦 2024-11-12 02:34:59

HTML5 规范在其“渲染”部分中有 CSS 规则 /a>“。只需选择您要查找的 rule 值并获取相应的 CSS。让我复制并粘贴 的规则:

注意:属性选择器中的“i”是 CSS4 且忽略大小写。即 rules=ROWSrules=rows 一样好。

table {
  box-sizing: border-box;
  border-spacing: 2px;
  border-collapse: separate;
  text-indent: initial;
}

table, td, th { border-color: gray; }
thead, tbody, tfoot, tr { border-color: inherit; }
table[rules=none i], table[rules=groups i], table[rules=rows i],
 ... and many more selectors in this fashion ...
table[rules=all i] > tfoot > tr > td, table[rules=all i] > tfoot > tr > th {
  border-color: black;
}

table[rules=none i], table[rules=groups i], table[rules=rows i],
table[rules=cols i], table[rules=all i] {
  border-style: hidden;
  border-collapse: collapse;
}

table[rules=none i] > tr > td, table[rules=none i] > tr > th,
table[rules=groups i] > tr > td, table[rules=groups i] > tr > th,
table[rules=rows i] > tr > td, table[rules=rows i] > tr > th 
   ... more selectors for none/groups/rows ...
{
  border-width: 1px;
  border-style: none;
}
table[rules=cols i] > tr > td, table[rules=cols i] > tr > th,
table[rules=cols i] > thead > tr > td, table[rules=cols i] > thead > tr > th,
table[rules=cols i] > tbody > tr > td, table[rules=cols i] > tbody > tr > th,
table[rules=cols i] > tfoot > tr > td, table[rules=cols i] > tfoot > tr > th {
  border-width: 1px;
  border-style: none solid;
}
table[rules=all i] > tr > td, table[rules=all i] > tr > th,
table[rules=all i] > thead > tr > td, table[rules=all i] > thead > tr > th,
table[rules=all i] > tbody > tr > td, table[rules=all i] > tbody > tr > th,
table[rules=all i] > tfoot > tr > td, table[rules=all i] > tfoot > tr > th {
  border-width: 1px;
  border-style: solid;
}

table[rules=groups i] > colgroup {
  border-left-width: 1px;
  border-left-style: solid;
  border-right-width: 1px;
  border-right-style: solid;
}
table[rules=groups i] > thead,
table[rules=groups i] > tbody,
table[rules=groups i] > tfoot {
  border-top-width: 1px;
  border-top-style: solid;
  border-bottom-width: 1px;
  border-bottom-style: solid;
}

table[rules=rows i] > tr, table[rules=rows i] > thead > tr,
table[rules=rows i] > tbody > tr, table[rules=rows i] > tfoot > tr {
  border-top-width: 1px;
  border-top-style: solid;
  border-bottom-width: 1px;
  border-bottom-style: solid;
}

The HTML5 spec has CSS rules in it’s section “Rendering“. Just pick the rule value you're looking for and fetch the corresponding CSS. Let me copy and paste the rules for <table rules=...>:

Note: the "i" in the attribute selector is CSS4 and ignores case. I.e. rules=ROWS is as good as rules=rows.

table {
  box-sizing: border-box;
  border-spacing: 2px;
  border-collapse: separate;
  text-indent: initial;
}

table, td, th { border-color: gray; }
thead, tbody, tfoot, tr { border-color: inherit; }
table[rules=none i], table[rules=groups i], table[rules=rows i],
 ... and many more selectors in this fashion ...
table[rules=all i] > tfoot > tr > td, table[rules=all i] > tfoot > tr > th {
  border-color: black;
}

table[rules=none i], table[rules=groups i], table[rules=rows i],
table[rules=cols i], table[rules=all i] {
  border-style: hidden;
  border-collapse: collapse;
}

table[rules=none i] > tr > td, table[rules=none i] > tr > th,
table[rules=groups i] > tr > td, table[rules=groups i] > tr > th,
table[rules=rows i] > tr > td, table[rules=rows i] > tr > th 
   ... more selectors for none/groups/rows ...
{
  border-width: 1px;
  border-style: none;
}
table[rules=cols i] > tr > td, table[rules=cols i] > tr > th,
table[rules=cols i] > thead > tr > td, table[rules=cols i] > thead > tr > th,
table[rules=cols i] > tbody > tr > td, table[rules=cols i] > tbody > tr > th,
table[rules=cols i] > tfoot > tr > td, table[rules=cols i] > tfoot > tr > th {
  border-width: 1px;
  border-style: none solid;
}
table[rules=all i] > tr > td, table[rules=all i] > tr > th,
table[rules=all i] > thead > tr > td, table[rules=all i] > thead > tr > th,
table[rules=all i] > tbody > tr > td, table[rules=all i] > tbody > tr > th,
table[rules=all i] > tfoot > tr > td, table[rules=all i] > tfoot > tr > th {
  border-width: 1px;
  border-style: solid;
}

table[rules=groups i] > colgroup {
  border-left-width: 1px;
  border-left-style: solid;
  border-right-width: 1px;
  border-right-style: solid;
}
table[rules=groups i] > thead,
table[rules=groups i] > tbody,
table[rules=groups i] > tfoot {
  border-top-width: 1px;
  border-top-style: solid;
  border-bottom-width: 1px;
  border-bottom-style: solid;
}

table[rules=rows i] > tr, table[rules=rows i] > thead > tr,
table[rules=rows i] > tbody > tr, table[rules=rows i] > tfoot > tr {
  border-top-width: 1px;
  border-top-style: solid;
  border-bottom-width: 1px;
  border-bottom-style: solid;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文