无法更改已访问链接的背景颜色

时间:2016-05-24 10:20:09

标签: html css

我正在尝试更改已访问链接的背景颜色,但我使用的CSS不起作用。如果有人可以帮助我会很棒。 我也尝试过重要的标签,但背景颜色仍然不会改变。

.fragment {
    font-size: 12px;
    font-family: tahoma;
    border-bottom: 1px solid #e8e8e8;
    height: 100%;
    padding: 10px;
    padding-bottom: 2px !important;
    text-decoration: none;
    display: block;
    box-sizing: border-box;
}

.fragment:visited { text-decoration: line-through; }
.fragment:hover {background-color:#f7f7f7; text-decoration: none;}

.fragment img { 
    float: left;
    margin-right: 10px;
}

.styleraise { 
    color: black;
    font-size: 18px;
    display: inline;
    font-family: 'Open Sans', sans-serif !important;
} 

.styleraise1 { 
    color: green;
    font-size: 15px;
    display: inline;
    font-family: 'Montserrat', sans-serif;
    margin-right: 6px;
    float:right;
}

.textpara {
    color:grey;
}

.imgbor {
border: 1px solid #e8e8e8;
}
<a class="fragment" href="google.com" target="_blank">
    <div>
    <img class="imgbor" src ="https://1.bp.blogspot.com/-NfU6VKEG__Q/V0P5yb-0vkI/AAAAAAAAABU/1ifpBLBKBpAcIdVXNvmbqt_Ygou2bHQdACLcB/s1600/realplayer.jpg" alt="some description"/> 
    <span class="styleraise">Download Real Player</span><span class="styleraise1">Real</span>
    <p class="textpara">
        Download RealPlayer for Free. Watch all your favorite videos. Plus, Download, Save, Organize and Share Videos.
    </p>
</div>
</a

2 个答案:

答案 0 :(得分:0)

添加我对Jainam的答案的评论,点击后将链接颜色更改为红色的方法将是以下代码。

请注意,只要有人留在页面上,这只会保持链接为红色。如果他们刷新或导航并返回,则链接不再是红色。

您可以选择存储已在Cookie中点击的链接,然后在用户返回页面时读取Cookie,并根据Cookie值再次将其设置为红色。

或者将人们发送到重定向页面,该页面将点击的链接保存在数据库中,然后根据存储的链接使链接变为红色。

&#13;
&#13;
$(".fragment").click(function(){
  $(".fragment").css('background','#FF0000');
});
&#13;
.fragment {
    font-size: 12px;
    font-family: tahoma;
    border-bottom: 1px solid #e8e8e8;
    height: 100%;
    padding: 10px;
    padding-bottom: 2px !important;
    text-decoration: none;
    display: block;
    box-sizing: border-box;
}

.fragment:visited { text-decoration: line-through; }
.fragment:hover {background-color:#f7f7f7; text-decoration: none;}


.fragment img { 
    float: left;
    margin-right: 10px;
}

.styleraise { 
    color: black;
    font-size: 18px;
    display: inline;
    font-family: 'Open Sans', sans-serif !important;
} 

.styleraise1 { 
    color: green;
    font-size: 15px;
    display: inline;
    font-family: 'Montserrat', sans-serif;
    margin-right: 6px;
    float:right;
}

.textpara {
    color:grey;
}

.imgbor {
border: 1px solid #e8e8e8;
}
.fragment:focus, .fragment:visited, .fragment:active {
  background-color: red;
  text-decoration: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="fragment" href="google.com" target="_blank">
    <div>
    <img class="imgbor" src ="https://1.bp.blogspot.com/-NfU6VKEG__Q/V0P5yb-0vkI/AAAAAAAAABU/1ifpBLBKBpAcIdVXNvmbqt_Ygou2bHQdACLcB/s1600/realplayer.jpg" alt="some description"/> 
    <span class="styleraise">Download Real Player</span><span class="styleraise1">Real</span>
    <p class="textpara">
        Download RealPlayer for Free. Watch all your favorite videos. Plus, Download, Save, Organize and Share Videos.
    </p>
</div>
</a>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

 first add css

.fragment:visited { text-decoration: line-through; background-color:green;}

<a class="fragment" href="https://www.google.co.in" target="_blank">

在您的超链接中提供完整的网址

首先,你错过了该类中的(片段:访问过的)背景颜色,并且在超链接中错过了完整的URL路径