【问题标题】:links and formatting, HTTP makes a difference?链接和格式,HTTP 有什么不同?
【发布时间】:2012-08-21 08:58:57
【问题描述】:

这就是我希望所有链接出现在页面上的方式:

a:link, a:visited {
    text-decoration: none;
    color: blue;
    font-weight: bold;
}

a:hover, a:active {
    text-decoration: underline;
    color: blue;
}

DIV 中的垂直导航菜单除外,其链接为白色和绿色背景(悬停时为蓝色)。注意:此 navMenu 仅链接到我网站上的其他页面(“home.html”、“contact.html”等)并使用相对路径(即 - 仅文件名)。

#navMenu {
    width: 105px;
    float: left;
    background-color: green;
    margin: 0px;
    padding: 0px;
}

#navMenu > ul {
    list-style-type: none;
    margin: 0px;
    padding: 0px;
    overflow: hidden;
}

#navMenu > ul li {
    display: inline;
    float: left;
    font-size: small;
}

#navMenu > ul li a:link, a:visited {
  display: block;
  width: 130px;
  font-weight: bold;
  color: white;
  background-color: #999900;
  text-align: left;
  padding: 4px;
  text-decoration: none;
  text-transform: uppercase;
}

#navMenu > ul li a:hover, a:active {
    background-color: blue;
}

因此,当我查看页面中位于 navMenu DIV 之外的链接时,大多数链接都是外部的(指向另一个站点)并且看起来像这样:

<a href="http://somewhere.com">Link</a>

并且正在使用蓝色,例如由默认的“a”选择器定义。

但是(得到这个) - 任何链接(即使它在 navMenu DIV 之外)指向网站上具有相对路径的另一个页面:

<a href="page2.html">Page 2</a>

正在使用 navManu 格式处理(因此文本为白色)。

但是得到这个 - 如果我在 navMenu DIV 之外获取任何这些链接(到内部页面)并且只是将“http://”添加到 HREF,它会从“a”选择器中获取并且链接变为蓝色。

什么?

【问题讨论】:

    标签: css html hyperlink anchor href


    【解决方案1】:

    那是因为您已经访问过该链接。您的 CSS 表示已访问的 任何 链接应显示为白色。第一个声明它应该是蓝色的声明被覆盖了,我认为这是你的问题。尝试将最后两个声明更改为以下内容:

    #navMenu > ul li a:link, #navMenu > ul li a:visited {
      display: block;
      width: 130px;
      font-weight: bold;
      color: white;
      background-color: #999900;
      text-align: left;
      padding: 4px;
      text-decoration: none;
      text-transform: uppercase;
    }
    
    #navMenu > ul li a:hover, #navMenu > ul li a:active {
      background-color: blue;
    }
    

    注意选择器的特殊性。

    【讨论】:

    • 我认为这与选择器有关。菜鸟的错误——对不起。感谢您的帮助!!!!
    • 没问题。很高兴我能帮上忙。
    猜你喜欢
    • 1970-01-01
    • 2012-03-24
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 2020-02-15
    • 2022-01-26
    • 2014-11-26
    相关资源
    最近更新 更多