Bootstrap 3 Tooltip over Glyphicon

前端 未结 5 1315
梦如初夏
梦如初夏 2020-12-25 12:00

Not sure if this even possible, I am trying to invoke a tooltip over a glyphicon inside an input group, my code (which does not work) is;

相关标签:
5条回答
  • 2020-12-25 12:40
    <span class="glyphicon glyphicon-info-sign icon_info" title="info"></span>
    

    Then add javascript code to initialize tooltip like below:

    $(".icon_info").tooltip();
    
    0 讨论(0)
  • 2020-12-25 12:42

    You can get a simple tooltip over the glyphicon using the title attribute (which is blank in your example).

    title="info"
    

    Working code

     // add this in your js
     // all the glyphicons having the class "my-tooltip" will show a tooltip if "title" attribute is present
     $(".my-tooltip").tooltip();
    
     <span class='glyphicon glyphicon-info-sign my-tooltip' title="here goes the tooltip text"></span>
    
    0 讨论(0)
  • 2020-12-25 12:48

    Using @MadJack's answer I rewrote your code and tested on JSFiddle.

    HTML:

    <div class="input-group" style='margin-top: 100px;'>
        <input type="text" class="form-control" name="security" id="security">
            <span class="input-group-addon">
                <a class='my-tool-tip' data-toggle="tooltip" data-placement="left" title="Tooltip here">
                    <!-- The class CANNOT be tooltip... -->
                    <i class='glyphicon glyphicon-info-sign'></i>
                </a>
            </span>
        </input>
    </div>
    

    JS:

    $("a.my-tool-tip").tooltip();
    

    Hope this helps,

    JSFiddle.

    -Andrew

    0 讨论(0)
  • 2020-12-25 13:04

    A Bootstrap newbie here...

    To use the Tooltip plugin with the glyph-icon, I've found success wrapping the glyph-icon span tag with an anchor tag having no href:

    <a data-toggle="tooltip" class="tooltipLink" data-original-title="Tooltip text goes here">
      <span class="glyphicon glyphicon-info-sign"></span>
    </a>
    

    Also, be sure to initialize the tooltips for the links with tooltips:

    $("a.tooltipLink").tooltip();
    

    I tested this with Bootstrap 3.03, jQuery 1.10.2 + Firefox 26, Chrome 32.0.1700, and IE 11.0.9600. So far, no hiccups.

    0 讨论(0)
  • 2020-12-25 13:05

    Using Bootstrap's Popover makes it a bit nice, Here is the documentation, and sample code snippet

    $(function () {
      $('.fa').popover({trigger: "hover"});
    })
    <!DOCTYPE html>
    <html>
    <head>
    <meta name="description" content="Information Popover snippet">
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>Information Popover snippet</title>
      <script src="https://code.jquery.com/jquery.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    </head>
    <body>  
      <span><i data-content="Simple Clean way to show more detailed information about anything" class="fa fa-question-circle"></i></span>
    </body>
    </html>

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