Is it possible to use pseudo-elements (:after, :before) inside a table row?

前端 未结 2 1235
Happy的楠姐
Happy的楠姐 2020-12-19 01:40

I want to add absolutely positioned element as an :after (of :before) of a table row.

Look at this:

相关标签:
2条回答
  • 2020-12-19 01:55

    Use the first table cell instead of the row as a host for the absolutely positioned pseudo-element.

    row > td:first-child::before {
      content: '';
      position: absolute;
      .
      .
    }
    
    0 讨论(0)
  • 2020-12-19 01:56

    In this example, you are using the ::after and ::before pseudo-elements to add content after or before a table row, which essentially will break the table layout and lead to unpredictable results.

    If you were to add the generated content to a table-cell, the results would be more consistent.

    There is not much to refer to except the original specification for generated content:

    http://www.w3.org/TR/2009/CR-CSS2-20090908/generate.html#before-after-content

    In addition, keep in mind that the CSS rendering engine generates anonymous boxes when creating tables:

    http://www.w3.org/TR/2009/CR-CSS2-20090908/tables.html#anonymous-boxes

    However, since generated content is not part of the DOM, the whole table-rendering process probably cannot deal with the extra pseudo-element in a sensible way.

    You are delving into an area that is not well specified and any support will be browser specific.

    Depending on your layout requirements, you might need to use JavaScript or jQuery to alter the DOM of the table to the desired effect.

    0 讨论(0)
提交回复
热议问题