有没有办法专门为包装标签内的标签设置样式?例如,我只想设置样式 <td>
在“宽”类的表中。
HTML:
<table class="wide">
<tr>
<td>Entry 1</td>
<td>Entry 2</td>
</tr>
<tr>
...
</tr>
</table>
CSS(或类似的东西):
td.wide {
/* styling */
}
我想要所有的<td>
“宽”表格的元素样式化但像 <table class="small"> ... </table>
这样的表格不会有它的 <td>
元素样式。我想避免添加 class="wide"
每<td>
所有宽表中的元素。
注意:我不打算专门针对 <table>
执行此操作和 <td>
元素。我想知道通常执行此操作的正确方法。该示例可以为所有 <p>
设置样式包含在 <div>
中的元素某个类(class)的。
最佳答案
Can HTML tags inherit the class of a parent/enclosing tag?
没有。类不是继承的。
Is there a way to specifically style only the tags inside a wrapping tag?
selector-of-container [space] selector-of-target-within-container
I would like to avoid adding
class="wide"
to every<td>
element in all the wide tables.
table.wide td { /* rules */ }
关于html - HTML 标签可以继承父/封闭标签的类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19006656/