How to hide an anchor tag by href #id using css

2019-03-26 06:16发布

I have different anchor tags with href=#ids and I need to hide them using a general css rule for all of them,

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?

6条回答
时光不老,我们不散
2楼-- · 2019-03-26 06:47

If you want to hide all a tags which have href set, you can do this:

a[href] { display: none; }
查看更多
Bombasti
3楼-- · 2019-03-26 06:50
#wrap a[href="#tab1"]{
display:none;
}
查看更多
来,给爷笑一个
4楼-- · 2019-03-26 06:55

Try using a[href*="#"] {display: none;} This selectors identifies a # in the href attribute of an anchor and if found it applies the style

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!

查看更多
小情绪 Triste *
5楼-- · 2019-03-26 07:04

Assuming #wrap is an id of a parent, you can use:

/* 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; }
查看更多
女痞
6楼-- · 2019-03-26 07:08

Try using attribute selectors:

a[href='#tab1']{ display: none }

Or even simply

[href='#tab1']{ display: none }

http://www.w3.org/TR/CSS2/selector.html

查看更多
相关推荐>>
7楼-- · 2019-03-26 07:10

Why not just create a CSS class for your anchors and hide them using that class?

<a href="#tab1" class="hiddenTab">foo</a>

And in your CSS:

a.hiddenTab {visibility:hidden; display:none;}

All the anchors you'd want to hide would just use "class='hiddenTab'"

查看更多
登录 后发表回答