Tooltip with HTML content without JavaScript

前端 未结 8 861
借酒劲吻你
借酒劲吻你 2020-11-30 00:24

There are plenty of JavaScript-based libraries that show tooltips when you hover your mouse over a certain area of a web page. Some are rather plain, some allow the tooltip

相关标签:
8条回答
  • 2020-11-30 00:57

    This is my solution for this:

    https://gist.github.com/BryanMoslo/808f7acb1dafcd049a1aebbeef8c2755

    The element recibes a "tooltip-title" attribute with the tooltip text and it is displayed with CSS on hover, I prefer this solution because I don't have to include the tooltip text as a HTML element!

    #HTML
    <button class="tooltip" tooltip-title="Save">Hover over me</button>
    
    #CSS
    
    body{
        padding: 50px;
    }
    .tooltip {
        position: relative;
    }
    
    .tooltip:before {
        content: attr(tooltip-title);
        min-width: 54px;
        background-color: #999999;
        color: #fff;
        font-size: 12px;
        border-radius: 4px;
        padding: 9px 0;
        position: absolute;
        top: -42px;
        left: 50%;
        margin-left: -27px;
        visibility: hidden;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .tooltip:after {
        content: "";
        position: absolute;
        top: -9px;
        left: 50%;
        margin-left: -5px;
        border-width: 5px;
        border-style: solid;
        border-color: #999999 transparent transparent;
        visibility: hidden;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .tooltip:hover:before,
    .tooltip:hover:after{
        visibility: visible;
        opacity: 1;
    }
    
    0 讨论(0)
  • 2020-11-30 01:02

    Using the title attribute:

    <a href="#" title="Tooltip here">Link</a>

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