CSS中的伪类选择器使用特定的id

时间:2015-04-16 16:45:49

标签: css css-selectors

如何将以下CSS仅应用于特定类,而不是我页面上的所有链接

a:link, a:visited {
    display: block;
    width: 149px;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #98bf21;
    text-align: center;
    padding: 4.7px;
    text-decoration: none;
    text-transform: uppercase;
}

1 个答案:

答案 0 :(得分:2)

如果它是您引用的类

,则在CSS中添加您的类
a.MyClass:link, a.MyClass:visited {
  display: block;
  width: 149px;
  font-weight: bold;
  color: #FFFFFF;
  background-color: #98bf21;
  text-align: center;
  padding: 4.7px;
  text-decoration: none;
  text-transform: uppercase;
  }

或id

 a#MyId:link, a#MyId:visited {
  display: block;
  width: 149px;
  font-weight: bold;
  color: #FFFFFF;
  background-color: #98bf21;
  text-align: center;
  padding: 4.7px;
  text-decoration: none;
  text-transform: uppercase;
  }