Is it possible to user pseudo-element (:after, :before) on table row safely?

丶灬走出姿态 提交于 2020-01-28 09:00:28

问题


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

Look at this http://jsbin.com/IGumoye/5/edit

I assume that when I add such element rendering engine (at least Webkit based) think it is a table cell of some kind.

:before works badly in all browsers. But :after works very well in Firefox and almost good in webkit. In webkit it keep small space and makes whole table width bigger.

- This is what bothers me in webkit.

How to fix this? And where can I read about why it happening?

UPDATE 1

Possible solution: Use first table cell in this row as a host for absolutely positioned element.

http://jsbin.com/IGumoye/10/edit

UPDATE 2

Ok, I think I found solution for my initial problem. And I assume there are might be better one. But I wanted to make using CSS by maximum. Problem is - make some static text editable and if user clicks anywhere else - close this edit mode.

http://jsbin.com/IGumoye/23/edit


回答1:


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.



来源:https://stackoverflow.com/questions/19588674/is-it-possible-to-user-pseudo-element-after-before-on-table-row-safely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!