what is wrong with my css? active links not changi

2019-03-04 10:01发布

问题:

I cannot get my Wordpress menu active links to remain red.

I've added the CSS I think is relevant to the navigation of, but also the body, etc, in case that is impacting the issue.

Thanks for your help!

body {
    font-family: 'Helvetica Neue', sans-serif;
    font-size: 12px;
    line-height: 18px; 
    color: #000;
}



/* 
LINKS 
*/

a:link,
a:visited {
    text-decoration: none;
    color: #000;
}

a:hover {
    text-decoration: none;
    color: #ff0000 ;
}

a:active {
    color: #ff0000;
}

h2.entry-title-index a:link,
h2.entry-title-index a:active,
h2.entry-title-index a:visited {
    text-decoration: none;
    color: #ff0000;
}

h2.entry-title-index a:hover {
    text-decoration: none;
    color: #ff0000;
} 

a:active {
    color: #ff0000 !important;
}

/* 
HEADLINES
*/

h2, #navigation {   
    font-family: 'Helvetica Neue', sans-serif;
    margin: 0;
    font-size: 16subpx;
    font-style: normal;
    font-variant: normal;
    font-weight: 450;
    line-height: 18px;
}

#navigation a:hover::before {
         content: '+ ';
}

#navigation a:active::before {
         content: '+ ';
}

#navigation ul a.active {
    color: #ff0000;
    }


h2.entry-title, h2.entry-title-index, h2.comment-title {
    margin-top:14px;
    color: #ff0000;
}

h2.entry-title, h2.comment-title {
/*  margin: 0 0 9px 0; */
}

h2.entry-title-index {
    line-height: 17px !important;
/*  margin: 9px 0 0 0  !important; */
}

回答1:

Active is only used while a user is clicking on an element, it's not meant to indicate which page is active. You should add a class to the active navigation item and style that class.

source: http://css-tricks.com/almanac/selectors/a/active/



回答2:

it doesn't work like that, you need to set active class or id with serverside language or with js, then you can indicate active page.