[英]Applying class to all children of an element
I'm wondering if it's possible (without using JS) to state that all children of tr.myRow
have a certain class. 我想知道是否有可能(不使用JS)声明
tr.myRow
所有孩子都有某个类。 I'm trying to use W3.CSS and I want every <td>
element to be w3-border
class. 我正在尝试使用W3.CSS,我希望每个
<td>
元素都是w3-border
类。 Now the code has to look like this: 现在代码必须如下所示:
<table class="w3-table">
<tr>
<td class="w3-border">A</td>
<td class="w3-border">B</td>
<td class="w3-border">C</td>
</tr>
</table>
which is not elegant. 这不优雅。
I would appreciate any hints 我会很感激任何提示
Regarding your question exactly as you worded it - you are not able to assign classes to HTML elements via bare CSS. 关于你的问题,正如你所说的那样 - 你无法通过裸CSS将类分配给HTML元素。 For this, specifically, you would need to use javascript, or a CSS extension like SCSS.
为此,具体而言,您需要使用javascript或像SCSS这样的CSS扩展。
I am, however, assuming you are trying to assign properties/values to the actual td
- which you wouldn't need class assignment for. 但是,我假设您正在尝试将属性/值分配给实际的
td
- 您不需要为其分配类。
tr.myRow * { /* Add your styles here */ }
This method does not answer your question, but does provide a way to produce the same result you are most likely looking for. 此方法不能回答您的问题,但确实提供了一种方法来生成您最有可能寻找的相同结果。
.w3-table tr td {//add your css}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.