Styling without href attribute

前端 未结 1 1200
面向向阳花
面向向阳花 2020-12-24 11:45

Is it possible to match all links without href specified via CSS?

Example:

Invalid link

I know its

1条回答
  •  醉梦人生
    2020-12-24 12:23

    Either use CSS3's :not():

    a:not([href]) {
        /* Styles for anchors without href */
    }
    

    Or specify a general style for all a, and one for a[href] to override it for those with the attribute.

    a {
        /* Styles for anchors with and without href */
    }
    
    a[href] {
        /* Styles for anchors with href, will override the above */
    }
    

    For the best browser support (includes ancient but not quite forgotten browsers), use the :link and :visited pseudo-classes instead of the attribute selector (combining both will match the same as a[href]):

    a {} /* All anchors */
    a:link, a:visited {} /* Override */
    

    Also see this answer for an in-depth explanation of a[href] versus a:link, a:visited.

    0 讨论(0)
提交回复
热议问题