仅将样式应用于第一级 td 标签

Apply style to only first level of td tags(仅将样式应用于第一级 td 标签)
本文介绍了仅将样式应用于第一级 td 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有没有办法将一个类的样式只应用到一个级别的 td 标签?

Is there a way to apply a Class' style to only ONE level of td tags?

<style>.MyClass td {border: solid 1px red;}</style>

<table class="MyClass">
  <tr>
    <td>
      THIS SHOULD HAVE RED BORDERS
    </td>
    <td>
      THIS SHOULD HAVE RED BORDERS
      <table><tr><td>THIS SHOULD NOT HAVE ANY</td></tr></table>
    </td>
  </tr>
</table>

推荐答案

有没有办法将一个类的样式只应用到一个级别的 td 标签?

Is there a way to apply a Class' style to only ONE level of td tags?

*:

.MyClass>tbody>tr>td { border: solid 1px red; }

但是!>"直接子选择器在 IE6 中不起作用.如果您需要支持该浏览器(唉,您可能会这样做),您所能做的就是单独选择内部元素并取消设置样式:

But! The ‘>’ direct-child selector does not work in IE6. If you need to support that browser (which you probably do, alas), all you can do is select the inner element separately and un-set the style:

.MyClass td { border: solid 1px red; }
.MyClass td td { border: none; }

<小时>

*请注意,第一个示例引用了 HTML 中未找到的 tbody 元素.它应该在您的 HTML 中,但浏览器通常可以忽略它......他们只是在幕后添加它.


*Note that the first example references a tbody element not found in your HTML. It should have been in your HTML, but browsers are generally ok with leaving it out... they just add it in behind the scenes.

这篇关于仅将样式应用于第一级 td 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)
Discord js reaction not detected(未检测到 Discord js 反应)
Joining a voice channel on ready (discord.js)(准备好加入语音频道(discord.js))
Cannot read properties of undefined when it shouldn#39;t be undefined in discord.js command handler(当不应该在 discord.js 命令处理程序中未定义时,无法读取未定义的属性)
Why messageReactionAdd do nothing discord.js(为什么 messageReactionAdd 什么都不做 discord.js)
How do I list all Members with a Role In Discord.Js(如何在 Discord.Js 中列出所有具有角色的成员)