css link color styles best practice

前端 未结 5 759
遇见更好的自我
遇见更好的自我 2020-12-08 04:30

There are many css-samples for styling color of links.

html5boilerplate.com offers such css code for link:

a { color: #00e; }
a:visited { color: #551         


        
5条回答
  •  离开以前
    2020-12-08 05:12

    Never remove that outline, or at least remove it only for a:active. If you do it for all anchors then it will be also removed for a:focus which is used for keyboard navigation. Also relying on hover too much is very bad since hover is not present on touch screens.

    I like to have all links easily distinguishable from the rest of the content. This is my personal preference:

    2016 version

    /* The order is important! Do not use fixed values like px! Always check contrast between text and background for accessibility! */
    
    a { border-bottom: thin solid;
        color: rgb(0,0,192);
        font-weight: bolder;
        text-decoration: none;
    }
    a:visited { color: rgb(160,0,160); }
    a:active { color: rgb(192,0,0); }
    a:active, a:focus, a:hover { border-bottom-width: medium; }
    


    2015 version

    a { border-bottom: thin solid;
        color: rgb(0,0,192);
        font-weight: 700;
        text-decoration: none;
    }
    a:visited { color: rgb(128,0,128); }
    a:active { color: rgb(192,0,0); } /* :active MUST come after :visited */
    a:active, a:focus, a:hover { border-bottom-width: medium; }
    


    2014 version

    a { border-bottom: 1px solid;
        color: rgb(0,0,166);
        font-weight: 700;
        text-decoration: none;
    }
    a:visited { color: rgb(122,0,122); }
    a:active { color: rgb(166,0,0); } /* :active MUST come after :visited */
    a:active, a:focus, a:hover { border-bottom: 3px solid; }
    


    2013 version

    a { color: rgb(0,0,166);
        font-weight: 700;
        border-bottom: 1px dotted;
        text-decoration: none;
    }
    a:visited { color: rgb(122,0,122); }
    a:hover, a:focus, a:active { border-bottom: 2px solid; }
    a:focus, a:active { color: rgb(166,0,0); }
    


提交回复
热议问题