css-背景色:#xxxxxx; not working

标签 css html anchor background-color

在我的导航栏中有这段代码。

<div id="aboutnav"><a class="hl" href="#"><h2>about\a</h2></a></div>

所有 div 在这种情况下所做的就是将文本放在适当的位置,而在 a.hl 中它是 -

a.hl{

background-color:#000;
text-decoraction:none;
color:#fff;

}

文本颜色正确,位置正确,但没有背景颜色。

最佳答案

这是因为在 HTML4/XHTML 中你不能将 hx 元素嵌套到 a!尝试改用它:

<div id="aboutnav"><h2><a class="hl" href="#">about\a</a></h2></div>

我认为您需要以类似的方式更新您的 css:

a.hl{
      display:block;
      background-color:#000;
      text-decoraction:none;
      color:#fff;    
}

关于css-背景色:#xxxxxx; not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7134274/

相关文章:

javascript - 为什么垂直滚动卡在移动 View 中?

c# - ASP :Button CSS :after Selector (or :before)

javascript - 显示/隐藏 div 中 <ul> 列表的多个分页

html - XSL - 遍历 XML 中的子节点

html - href ="mailto:"不适用于任何浏览器

html - 固定页眉与页内 anchor 重叠

javascript - document.getElementById().style.display = 'none' ;仅适用于 Firefox

css - 缩小时 Div 会移动。当我有奇数时如何使用百分比?

html - 在 Bootstrap 中垂直对齐文本

html - anchor 标记元素之间的 CSS 不需要的间距