.Current link styling on CSS only works on the 1st page and doesn't transfer to the other

◇◆丶佛笑我妖孽 提交于 2020-01-06 03:51:19

问题


So the css that I have works for both html pages, however, the current link styling only works on the first page and doesn't transfer to the 2nd page when clicked. Do you know why this would be?

css that handles the current link styling

li.current > a:link {
    border-bottom: 0.3px solid #000000;
}

1st page html (works on this)

<!--Header-->
<header class="boxed" id="header-white">
    <div class="header-margin">
        <div class="logo"><a class="ajax-link" href="index-2.html">DAVIT AVOYAN</a></div>
        <ul class="header-nav">
            <li class = "current"><a class="ajax-link" href="index-2.html">UX PORTFOLIO</a></li>
            <li><a class="ajax-link" href="about-me.html">About me</a></li>
        </ul>

2nd html page (works on this one, only if opened first)

<!--Header-->
<header class="boxed" id="header-white">
    <div class="header-margin">
        <div class="logo"><a class="ajax-link" href="index-2.html">DAVIT AVOYAN</a></div>
        <ul class="header-nav">
            <li><a class="ajax-link" href="index-2.html">UX PORTFOLIO</a></li>
            <li class = "current"><a class="ajax-link" href="about-me.html">About me</a></li>
        </ul>

回答1:


Please try below css for get link in second page. You need to put "a:visited" property.

<style type="text/css">
    li.current > a:link {
        border-bottom: 0.3px solid green;
        color: red;
    }
    li.current > a:visited {
        border-bottom: 0.3px solid green;
        color: red;
    }
</style>



回答2:


The behavior you're seeing is expected. The :link pseudo-class refers to links that have never been visited. By definition, the user must have clicked the link to the current page to get to it, so it will not be selected by :link.

You need to use li.current > a:visited.



来源:https://stackoverflow.com/questions/34349803/current-link-styling-on-css-only-works-on-the-1st-page-and-doesnt-transfer-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!