2013-08-02 40 views
1

我的HTML和CSS文件设置正确,但我遇到了某个选择器的问题。CSS选择器不改变链接颜色

我这里的HTML:

<span id="bottom_nav_bar"> 
    <a href="#">Link 1</a> 
</span> 

而且这里的CSS:

a#bottom_nav_bar{ color: red; text-align: center; } 

然而,我的跨度中,无法选择,我想不通为什么。有任何想法吗?

回答

1

试试这个:

#bottom_nav_bar a{ color: red; text-align: center; } 
+0

这工作非常感谢! –

3

应该改为:

#bottom_bar_nav a { 
    color: red; 
    text-align: center; 
} 

由于<a><span>与ID bottom_nav_bar

+0

啊我到处都找不到这种解决办法,谢谢! –

0

使用后代这个选择跨度链接

span #bottom_nav_bar a{ color: red; text-align: center; } 
+0

我非常感谢你的回答类型先生:) –

3

你不针对a元素。您的CSS选择器正在尝试使用“bottom_nav_bar”的ida元素进行样式设置。但是,在您的HTML中,跨度具有此ID,并且锚点元素位于跨度范围内。

要定位锚标记,你的CSS选择器更改为:

#bottom_nav_bar a { color: red; text-align: center; } 

仅定位跨度,改变a#bottom_nav_barspan#bottom_nav_bar

有关选择器的详细信息,请参阅http://www.w3.org/TR/css3-selectors/#selectors

+0

非常感谢你,我忽略了这个 –

0

您的链接没有这个ID,所以它不能工作...

把你的ID给一个标签;)

+0

非常感谢你非常Fabi –