Can an abbr tag's title be styled?

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

Take the following code:

WHO

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

4条回答
  •  梦毁少年i
    2021-01-04 19:10

    I was looking for something similar and came up with the following alternative (tested on Firefox, Safari and Chrome on Mac, works with IE 7-10 when I clicked it), based on this link:

    HTML:

    Abbreviation
    

    jQuery:

    $('[title]').each( function() {
        var mytitle = $(this);
        mytitle.data('title',mytitle.attr('title')); // get title attribute value
    mytitle.attr('name', mytitle.attr('title')); // add title attribute value to NAME attribute
        mytitle.removeAttr('title'); // remove the title attribute, removing browser tooltip
    });
    

    CSS:

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

提交回复
热议问题