html - 将样式应用于 tr 中包含的 td

标签 html css

<分区>

我有这样的问题,我有类似的事情:

    <tr>
      <td class="someclass">
        <input />
      </td>
    ...
      <td> </td>
      <td> </td>
     ..
    </tr>

我想覆盖将仅应用于第一个 <td> 的“someclass”css 类与 <input> .我该怎么做?也许有父规范或类似的东西?注意:我不能添加新类

最佳答案

可以使用css伪类first-child

Supported from IE7 +

.someclass{background:red;}
#table1 tr > td:first-child {background:blue;}
<table id="table1">
<tr>
<td class="someclass">One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>  

请引用这个link了解更多关于 css 选择器的信息

关于html - 将样式应用于 tr 中包含的 td,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34395023/

上一篇:javascript - 为多个实例使用复选框

下一篇:html - Bootstrap 堆叠行在响应式中不起作用

相关文章:

javascript - 如何改变网页上文本框的大小?

css - 你可以在 css 中除以 xvw 吗?

c# - 停止从用户代理继承

html -/site_media/base.css 末尾的 "v=747"有什么用?v=747"

javascript - 如何识别元素上的 css 属性是在 'px' 还是 'vw' 单元?

html - 我们可以在 bootstrap 4 中使用部分崩溃概念吗?

html - 页脚不是 100% 底部跨浏览器

html - 我可以通过语义或结构来区分 HTML 吗?

jquery - OnClick 事件在下拉选项中不起作用

CSS背景图片以适应高度,宽度应按比例自动缩放