Html 如何使用 css 通过 href #id 隐藏锚标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9165479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide an anchor tag by href #id using css
提问by Jces
I have different anchor tags with href=#ids and I need to hide them using a general css rule for all of them,
我有不同的带有 href=#ids 的锚标签,我需要使用通用的 css 规则来隐藏它们,
Content xxxxxxxxx <a href="#tab1">Table 1</a>.Content xxxxxxxxxxxx <a href="#tab2">Table 2</a>
I was trying to use something like this:
我试图使用这样的东西:
#wrap a='#tab1'{
display:none;
}
Any idea how to do it?
知道怎么做吗?
回答by graphicdivine
Try using attribute selectors:
尝试使用属性选择器:
a[href='#tab1']{ display: none }
Or even simply
甚至干脆
[href='#tab1']{ display: none }
回答by Tim
Why not just create a CSS class for your anchors and hide them using that class?
为什么不为您的锚点创建一个 CSS 类并使用该类隐藏它们?
<a href="#tab1" class="hiddenTab">foo</a>
And in your CSS:
在你的 CSS 中:
a.hiddenTab {visibility:hidden; display:none;}
All the anchors you'd want to hide would just use "class='hiddenTab'"
您想隐藏的所有锚点都将使用“class='hiddenTab'”
回答by frazras
#wrap a[href="#tab1"]{
display:none;
}
回答by Junaid Anwar
Try using a[href*="#"] {display: none;}
This selectors identifies a # in the href
attribute of an anchor and if found it applies the style
尝试使用a[href*="#"] {display: none;}
此选择器标识href
锚属性中的# ,如果找到则应用该样式
You can use it in another way such as
header a[href*="#"] {display: none;}
So you don't mess all the anchors on the site!
您可以通过另一种方式使用它,例如
header a[href*="#"] {display: none;}
这样您就不会弄乱网站上的所有锚点!
回答by Ninja
If you want to hide all a tags which have href set, you can do this:
如果你想隐藏所有设置了 href 的标签,你可以这样做:
a[href] { display: none; }
回答by Sagar Patil
Assuming #wrap
is an id of a parent, you can use:
假设#wrap
是父母的 id,您可以使用:
/* Hide all anchor tags which are children of #wrap */
#wrap a{ display:none; }
/* Hide all anchor tags which are direct children of #wrap */
#wrap > a{ display:none; }
/* Hide a specific anchor tag (Probably won't work in IE6 though) */
a[href="#tab1"]{ display:none; }