HTML Anchor, Disable Style

后端 未结 3 412
悲&欢浪女
悲&欢浪女 2021-02-06 21:48

I have some html anchor link code, and unlike the rest of document I want it to look like it is not a link.

Is there a simple way to disable the style change caused by w

相关标签:
3条回答
  • 2021-02-06 22:33

    Setting color to black and text-decoration to explicitly none is a little more aggressive than worked for me.

    I was looking for the CSS of the anchors to be "benign" and just blend into the existing CSS. Here's what I went with:

    a.nostyle:link {
        text-decoration: inherit;
        color: inherit;
        cursor: auto;
    }
    
    a.nostyle:visited {
        text-decoration: inherit;
        color: inherit;
        cursor: auto;
    }
    

    Then I just added the CSS nostyle class to the anchors that I wanted to be unformatted.

    0 讨论(0)
  • 2021-02-06 22:41

    If you don't care about IE, you can attach :not(#exclude) (where exclude is the ID of the link in question) to your link styles:

    a:link:not(#exclude), a:visited:not(#exclude) {
        text-decoration: none;
        color: blue;
        cursor: pointer;
    }
    

    Otherwise I don't think you can brute-force it the way you describe. You can either use an inline style instead (not recommended) or you can use a special class/ID assigned to that link, whose selector you'd group with body. For example, if you had these styles:

    body {
        text-decoration: none;
        color: black;
        cursor: auto;
    }
    
    a:link, a:visited {
        text-decoration: none;
        color: blue;
        cursor: pointer;
    }
    

    You can simply toss in a more specific selector, that'd match that link, onto the body rule:

    body, #exclude {
        text-decoration: none;
        color: black;
        cursor: auto;
    }
    
    a:link, a:visited {
        text-decoration: none;
        color: blue;
        cursor: pointer;
    }
    
    0 讨论(0)
  • 2021-02-06 22:47

    I achieved this by creating a class .reset-a and targeting all of its' pseudo classes.

    Targeting of all pseudo classes is important to make it flawless.

    outline: 0 property removes the dotted border that surrounds a link when it is focused or active.

    .reset-a, .reset-a:hover, .reset-a:visited, .reset-a:focus, .reset-a:active  {
      text-decoration: none;
      color: inherit;
      outline: 0;
      cursor: auto;
    }
    
    0 讨论(0)
提交回复
热议问题