問題描述
有沒有辦法將一個類的樣式只應(yīng)用到一個級別的 td 標(biāo)簽?
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>
推薦答案
有沒有辦法將一個類的樣式只應(yīng)用到一個級別的 td 標(biāo)簽?
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 中不起作用.如果您需要支持該瀏覽器(唉,您可能會這樣做),您所能做的就是單獨(dú)選擇內(nèi)部元素并取消設(shè)置樣式:
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
元素.它應(yīng)該在您的 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.
這篇關(guān)于僅將樣式應(yīng)用于第一級 td 標(biāo)簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!