Add line break within tooltips

后端 未结 27 2307
北恋
北恋 2020-11-28 02:23

How can line breaks be added within a HTML tooltip?

I tried using
and \\n within the tooltip as follows:



        
相关标签:
27条回答
  • 2020-11-28 02:35

    Just use the entity code 
 for a linebreak in a title attribute.

    <a title="First Line &#xA;Second Line">Hover Me </a>

    0 讨论(0)
  • 2020-11-28 02:39

    it is possible to add linebreaks within native HTML tooltips by simply having the title attribute spread over mutliple lines.

    However, I'd recommend using a jQuery tooltip plugin such as Q-Tip: http://craigsworks.com/projects/qtip/.

    It is simple to set up and use. Alternatively there are a lot of free javascript tooltip plugins around too.

    edit: correction on first statement.

    0 讨论(0)
  • 2020-11-28 02:39
    AngularJS with Bootstrap UI Tolltip (uib-tooltip), has three versions of tool-tip:
    

    uib-tooltip, uib-tooltip-template and uib-tooltip-html

    - uib-tooltip takes only text and will escape any HTML provided
    - uib-tooltip-html takes an expression that evaluates to an HTML string
    - uib-tooltip-template takes a text that specifies the location of the template
    

    In my case, I opted for uib-tooltip-html and there are three parts to it:

    1. configuration
    2. controller
    3. HTML

    Example:

    (function(angular) {
    
    //Step 1: configure $sceProvider - this allows the configuration of $sce service.
    
    angular.module('myApp', ['uib.bootstrap'])
           .config(function($sceProvider) {
               $sceProvider.enabled(false);
           });
    
    //Step 2: Set the tooltip content in the controller
    
    angular.module('myApp')
           .controller('myController', myController);
    
    myController.$inject = ['$sce'];
    
    function myController($sce) {
        var vm = this;
        vm.tooltipContent = $sce.trustAsHtml('I am the first line <br /><br />' +
                                             'I am the second line-break');
    
        return vm;
    }
    
     })(window.angular);
    
    //Step 3: Use the tooltip in HTML (UI)
    
    <div ng-controller="myController as get">
         <span uib-tooltip-html="get.tooltipContent">other Contents</span>
    </div>
    

    For more information, please check here

    0 讨论(0)
  • 2020-11-28 02:40

    This CSS is what finally worked for me in conjunction with a linefeed in my editor:

    .tooltip-inner {
        white-space: pre-wrap;
    }
    

    Found here: How to make Twitter bootstrap tooltips have multiple lines?

    0 讨论(0)
  • 2020-11-28 02:43

    Use

    &#013
    

    There shouldn't be any ; character.

    0 讨论(0)
  • 2020-11-28 02:43

    Hi this code will work in all browser !!i used for new line in chrome and safari and ul li for IE

     function genarateMultiLIneCode(){
            var =values["a","b","c"];
            const liStart = '<li>';
                  const liEnd = '</li>';
                  const bullet = '&#8226; ';     
                  var mergedString = ' ';
                  const unOrderListStart='<ul>'
                  const unOrderListEnd='</ul>'
                  const fakeNewline = '&#013;&#010;';
                  for (let i = 0; i < values.length; i++) {
                       mergedString += liStart + bullet + values[i] + liEnd + fakeNewline;
                  }
                  const tempElement = document.createElement("div");
                  tempElement.innerHTML = unOrderListStart + mergedString + unOrderListEnd;    
                  return tempElement.innerText;
                }
            }
    
    0 讨论(0)
提交回复
热议问题