【问题标题】:Bootstrap - Change the color of visited linksBootstrap - 更改访问链接的颜色
【发布时间】:2016-11-26 10:48:35
【问题描述】:

我希望所有链接在被访问时都改变颜色。我正在使用 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>

感谢您的帮助

【问题讨论】:

    标签: html css twitter-bootstrap hyperlink


    【解决方案1】:

    您使用的是 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; }
    

    【讨论】:

    • 这行得通。您也可以删除!important;
    • 我也会推荐@TedGoas。
    【解决方案2】:

    您编写的“css”实际上是“Sass”,只有在您编译它时才能工作。 要更改颜色,请将&amp; 替换为a,并将&amp; 的所有内容移到括号外,如下所示:

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

    【讨论】:

      【解决方案3】:

      试试这个不需要使用 !important

      body a {
          color: #d99a30;
      }
      body a:hover{
         color:red;
        }
      
      body a:visited{
          color:black;
        }
      <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">
      
          
          </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>

      【讨论】:

        【解决方案4】:

        您可以为所有超链接使用自定义 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>

        【讨论】:

          【解决方案5】:
          a:link, a:visited {
               color:#FFFFFF;
          }
          
          a:hover {
              color: #2DC2E8;
          }
          

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

          谢谢!

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-07-21
            • 2018-12-01
            • 2019-09-05
            • 2015-12-06
            • 1970-01-01
            • 2013-01-02
            • 2013-06-23
            • 1970-01-01
            相关资源
            最近更新 更多