如何使用css通过href #id隐藏锚标记

时间:2022-04-03 20:30:45

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?

知道怎么做吗?

6 个解决方案

#1


14  

Try using attribute selectors:

尝试使用属性选择器:

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

Or even simply

甚至简单

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

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

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

#2


11  

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'”

#3


3  

#wrap a[href="#tab1"]{
display:none;
}

#4


2  

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

尝试使用[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!

你可以用另一种方式使用它,比如标题a [href * =“#”] {display:none;}所以你不要弄乱网站上的所有锚点!

#5


1  

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

如果要隐藏所有已设置href的标记,可以执行以下操作:

a[href] { display: none; }

#6


0  

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; }

#1


14  

Try using attribute selectors:

尝试使用属性选择器:

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

Or even simply

甚至简单

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

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

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

#2


11  

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'”

#3


3  

#wrap a[href="#tab1"]{
display:none;
}

#4


2  

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

尝试使用[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!

你可以用另一种方式使用它,比如标题a [href * =“#”] {display:none;}所以你不要弄乱网站上的所有锚点!

#5


1  

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

如果要隐藏所有已设置href的标记,可以执行以下操作:

a[href] { display: none; }

#6


0  

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; }