Can an abbr tag's title be styled?

前端 未结 4 1473
闹比i
闹比i 2021-01-04 18:10

Take the following code:

WHO

Can we style an abbr tag\'s title? So that instea

4条回答
  •  生来不讨喜
    2021-01-04 18:51

    Actually, Alex Mcp’s answer is incorrect. It is entirely possible to do this with CSS for modern browsers. However, a fallback for older browsers with JavaScript may be used.

    abbr {
        position: relative;
    }
    
    abbr:hover::after {
        position: absolute;
        bottom: 100%;
        left: 100%;
        display: block;
        padding: 1em;
        background: yellow;
        content: attr(title);
    }
    

    This will add an absolutely positioned pseudo element top right of the abbr tag using the attribute content within the title when the abbr tag is hovered over.

提交回复
热议问题