CSS - modify parent based on first child

安稳与你 提交于 2020-01-06 08:49:16

问题


Is there a way in CSS to modify the parent element, given the first child?

In my case, this would be to format a table cell differently if the first child is a link.

<td>Hello</td>
<td><a href="go.html">Go here!</a></td>

<style>
td { padding: 5px; } /* Normal cell */
?? { padding: 0px; } /* Cell with link as first child */
</style>

回答1:


No, but you can think of a different approach and do something like:

td { padding: 5px; } /* Normal cell */
td a { margin: -5px; } /* Cell with link as first child */

There are many other ways to do the similar, of course.

CSS4 should offer a :has pseudo class which would do exactly what you wanted, but we need to wait for it.



来源:https://stackoverflow.com/questions/25747188/css-modify-parent-based-on-first-child

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