我的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; }
然而,我的跨度中,无法选择,我想不通为什么。有任何想法吗?
我的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; }
然而,我的跨度中,无法选择,我想不通为什么。有任何想法吗?
试试这个:
#bottom_nav_bar a{ color: red; text-align: center; }
应该改为:
#bottom_bar_nav a {
color: red;
text-align: center;
}
由于<a>
是<span>
与ID bottom_nav_bar
啊我到处都找不到这种解决办法,谢谢! –
使用后代这个选择跨度链接
span #bottom_nav_bar a{ color: red; text-align: center; }
我非常感谢你的回答类型先生:) –
你不针对a
元素。您的CSS选择器正在尝试使用“bottom_nav_bar”的id
对a
元素进行样式设置。但是,在您的HTML中,跨度具有此ID,并且锚点元素位于跨度范围内。
要定位锚标记,你的CSS选择器更改为:
#bottom_nav_bar a { color: red; text-align: center; }
仅定位跨度,改变a#bottom_nav_bar
到span#bottom_nav_bar
。
有关选择器的详细信息,请参阅http://www.w3.org/TR/css3-selectors/#selectors
非常感谢你,我忽略了这个 –
您的链接没有这个ID,所以它不能工作...
把你的ID给一个标签;)
非常感谢你非常Fabi –
这工作非常感谢! –