[英]css- background-color:#xxxxxx; not working
in my navigation bar i have this code. 在我的导航栏中,我有此代码。
<div id="aboutnav"><a class="hl" href="#"><h2>about\a</h2></a></div>
all the div does in the case is put the text in position and in the a.hl it's - div在这种情况下所做的全部工作就是将文本放在适当的位置,并将其放在a.hl中-
a.hl{
background-color:#000;
text-decoraction:none;
color:#fff;
}
the text is the right colour, it is in the correct position but there is no background colour. 文字是正确的颜色,位置正确,但没有背景色。
This is because in HTML4/XHTML you can't nest hx elements into a! 这是因为在HTML4 / XHTML中,您不能将hx元素嵌套到a中! Try using this instead:
尝试使用此代替:
<div id="aboutnav"><h2><a class="hl" href="#">about\a</a></h2></div>
I think you would need to update your css in a similar way: 我认为您将需要以类似的方式更新CSS:
a.hl{
display:block;
background-color:#000;
text-decoraction:none;
color:#fff;
}
Your style is probably being overridden by another style for h2
. 您的样式可能已被
h2
的另一种样式覆盖。 Try: 尝试:
a.h1 h2{
background-color: #000;
}
You should write the HTML like this 您应该这样编写HTML
<div id="aboutnav">
<h2>
<a class="hl" href="#">about</a>
</h2>
</div>
And then style it like so 然后像这样样式
#aboutnav h2 {
background-color:#000;
}
#aboutnav h2 a {
text-decoration:none;
color:#fff;
}
Example: http://jsfiddle.net/jasongennaro/rbxBL/ 示例: http : //jsfiddle.net/jasongennaro/rbxBL/
Fyi... you had text-decoration
misspelled. Fyi ...您的
text-decoration
拼写错误。
Also, you really don't need the class for the a
when the HTML is done this way. 此外,你真的不需要在类的
a
当HTML完成这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.