Add tooltip to font awesome icon

后端 未结 6 711
情深已故
情深已故 2021-02-11 13:06

Has anyone here added tooltips to font-awesome icons?

I have the following jsfiddle, but cannot seem to find a guide to add tooltips to the icons.



        
6条回答
  •  生来不讨喜
    2021-02-11 13:25

    In regards to this question, this can be easily achieved using a few lines of SASS;

    HTML:

    
    

    CSS output would be:

    a[data-tool-tip]{
        position: relative;
        text-decoration: none;
        color: rgba(255,255,255,0.75);
    }
    
    a[data-tool-tip]::after{
        content: attr(data-tool-tip);
        display: block;
        position: absolute;
        background-color: dimgrey;
        padding: 1em 3em;
        color: white;
        border-radius: 5px;
        font-size: .5em;
        bottom: 0;
        left: -180%;
        white-space: nowrap;
        transform: scale(0);
        transition: 
        transform ease-out 150ms,
        bottom ease-out 150ms;
    }
    
    a[data-tool-tip]:hover::after{
        transform: scale(1);
        bottom: 200%;
    }
    

    Basically the attribute selector [data-tool-tip] selects the content of whatever's inside and allows you to animate it however you want.

提交回复
热议问题