Bootstrap - 更改已访问链接的颜色

时间:2016-07-22 13:42:05

标签: html css twitter-bootstrap hyperlink

我希望所有链接在访问时都会改变颜色。我正在使用Bootstrap,这是我到目前为止所尝试的(无法正常工作):

<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="unicode">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">

        <!--[if lt IE 9]>
          <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">

        <style type="text/css">
               a{
                 color:#d99a30 !important;
                 &:hover{ color:#37404e !important;}
                 &:visited{ color:#37404e !important;}
               }
        </style>
    </head>
    <body>
        <div class="container">
             <div class="col-md-8 col-md-offset-2">
                  <div class="row">
                       <div class="col-sm-12">
                            <h3><a href="some_link.html">Link</a></h3>
                       </div>
                  </div>
             </div>
        </div>
    </body>

感谢您的帮助

5 个答案:

答案 0 :(得分:5)

您正在使用LESS / SASS的语法而不是纯CSS。以下是使用CSS的代码示例。

a { color:#d99a30 !important; }
a:hover { color:#37404e !important; }
a:visited { color:#37404e !important; }

如果您希望:hover:visited相同,您也可以简化该规则:

a { color:#d99a30 !important; }
a:hover, a:visited { color:#37404e !important; }

答案 1 :(得分:0)

您可以将自定义css用于所有超链接。你应该使用!important和你的自定义css,否则这个css不起作用。

a {
    color: blue !important;
    text-decoration: none !important;
}
a:link, a:visited {
    color: blue !important;
}
a:hover {
    color: red !important;
}
<a href="http://www.w3schools.com">W3Sschools Home</a><br>
<a href="http://www.w3schools.com/html/">W3Schools HTML Tutorial</a><br>
<a href="http://www.w3schools.com/css/">W3Schools CSS Tutorial</a>

<p><b>Note:</b> The :visited selector style links to pages you have already visited.</p>

答案 2 :(得分:0)

你写的'css'实际上是'Sass',只有在编译它时才会起作用。 要更改颜色,请将&替换为a,并使用括号外的&移动所有内容,如下所示:

a{
   color:#d99a30 !important;
}

a:hover, a:visited{
   color:#37404e !important;
}

答案 3 :(得分:0)

尝试这个不需要使用!important

    window.onload = function slider() {
        $('#img1').show('fade', 500);
        $('#img1').delay(5000).hide("slide",{direction:'left'},500);
    }

    var length = $('li').length();
    console.log(length);
    var count = 2;
    setInterval(function () {
        $('#img' + count).show('slide', { direction: 'right' }, 500);
        $('#img' + count).delay(5500).hide('slide', { direction: 'left' }, 500);

        if (count === sc) {
            count = 1;
        } else {
            count += 1;
        }
    }, 6500);
body a {
    color: #d99a30;
}
body a:hover{
   color:red;
  }

body a:visited{
    color:black;
  }

答案 4 :(得分:0)

a:link, a:visited {
     color:#FFFFFF;
}

a:hover {
    color: #2DC2E8;
}

上面的代码对我有用...因为我希望被“访问”的链接看起来好像没有悬停一样。

谢谢!