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

编程入门 行业动态 更新时间:2024-10-27 02:19:04
本文介绍了仅将样式应用于第一级 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 标签

本文发布于:2023-07-13 03:19:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1099785.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用于   样式   标签   td

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!