首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在div中隐藏特定的表。

在div中隐藏特定的表。
EN

Stack Overflow用户
提问于 2014-09-04 16:14:22
回答 3查看 54关注 0票数 0

我的sharepoint页面中有以下HTML:

代码语言:javascript
复制
<div id="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">

<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
</div>

现在,除了第三个表之外,我想隐藏div中的所有表。有人能告诉我吗?我曾经用以下方法隐藏第一张表:-

代码语言:javascript
复制
#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView > table:first-child { display: none !important;
 }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-09-04 16:16:39

使用:not:nth-child(n)选择器:

代码语言:javascript
复制
#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView > table:not(:nth-child(3)) {
    display: none;
}
  • :not(selector)选择每个元素,除了一个与父代内的选择器匹配的元素。
  • nth-child选择其父元素的第n个子元素。

也是

避免使用!important,除非您真的需要它。它会弄乱你的代码。

票数 5
EN

Stack Overflow用户

发布于 2014-09-04 16:19:36

您可以使用:not选择器。

代码语言:javascript
复制
#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView > table:not(:nth-child(3)) { 
    display: none !important;
 }

:not选择的不是其中提到的child-element

!important重写用于表的任何以前的属性。

票数 1
EN

Stack Overflow用户

发布于 2014-09-04 16:31:24

在需要支持IE8或更低版本的情况下,:not / :nth-child选择器将不受支持(尽管IE8支持:first-child )。如果是这样的话,我建议在第三个表中添加一些内联样式。

HTML:

代码语言:javascript
复制
<div id="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0; display:block;">

<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
</div>

CSS:

代码语言:javascript
复制
#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView > table { display:none; }

我不认为您应该有任何问题的CSS覆盖您的内联样式,但如果发生这种情况,您可以考虑使用!important。虽然使用!important通常不是很好的实践,需要仔细考虑,但如果支持IE8是必要的,我倾向于使用它。

代码语言:javascript
复制
<table cellspacing="0" cellpadding="0" style="border-width:0; display:block !important;">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25670340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档