如何为第一个< td>设置样式表格中包含在表格中的元素 [英] How to style first <td> element in table that is contained in a form

查看:186
本文介绍了如何为第一个< td>设置样式表格中包含在表格中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个表格:

<form>
  <table>
    <tbody>
      <tr>
        <td style="font-family : Arial">
          Sample text
        </td>
      </tr>
    </tbody>
  </table>
</form>

由于我没有ID,我该如何添加新样式到此表单的第一个,这就是我到目前为止所拥有的:

How can I add append a new style to just the first of this form since I do not have its id, here is what I have so far :

form table tbody tr td{
    font-family : Arial;
    font-weight: bold;
}

推荐答案

我将按照此处的其他答案使用第一个孩子,但是您不必对其余CSS规则如此具体.例如,以下规则就足够了:

I would use first-child as per the other answers here, but you don't necessarily need to be so specific with the rest of the css rule. For example the rule below should suffice:

form td:first-child {
    font-family: Arial;
    font-weight: bold;
}

您的css不仅更易于理解和调试,而且在您需要时不必覆写此规则也将更容易覆盖该规则.

Not only will your css be easier to understand and debug but it will be simpler to override this rule should you need to without having to get uber specific with other rules.

这篇关于如何为第一个&lt; td&gt;设置样式表格中包含在表格中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆