Bootstrap popover hides line breaks

HtmlTwitter BootstrapPopover

Html Problem Overview


I am using the html code as follows to show the bootstrap popover

<a data-original-title="" data-content="Hi,
           Welcome !

           Sincerely,
             programmer
           "
   data-placement="bottom">
    content
</a>

And I initialized the popover as follows

$(this).popover({
            html:true
        });

All works fine but the problem is the content available in data-content not displayed with the spaces....It removes all the new lines and show it in the single line ....How can i overcome this....

Html Solutions


Solution 1 - Html

You need to use <br/> for new line in html or use a <pre> tag

Ensure the data-html="true" attribute is present.

Solution 2 - Html

You can use white-space: pre-wrap; to preserve line breaks in formatting. There is no need to manually insert html elements.

.popover {
    white-space: pre-wrap;    
}

Solution 3 - Html

To add on to Arun P Johny's solution, if you find that your <br /> tags in the data-content value are rendering as plain text in the popover content on the page, add the additional attribute data-html="true", like so:

<a data-content="Hi,<br />Welcome !<br /><br />Sincerely,<br />programmer"
        data-html="true"
        data-placement="bottom">
    content
</a>

Be aware that using data-html="true" does introduce a potential vulnerability to XSS attacks; don't use it with unsanitized user input.

Docs: https://getbootstrap.com/docs/3.3/javascript/#popovers-options

Solution 4 - Html

I managed to get this working by adding \n to my popover text where I want the lines to break and adding the following to my stylesheet:

.popover {
    white-space: pre-line;    
}

Thanks for the help, everyone!

Solution 5 - Html

We managed to use the styling of white-space: pre-wrap except we found that added extra whitespace to the whole pop-over. Instead we added this styling to the popover-content.

.popover-content {
    white-space: pre-wrap;
}

Solution 6 - Html

You just need to add data-html="true" to your tag then all your html tags inside the help text work fine,

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAravindhanView Question on Stackoverflow
Solution 1 - HtmlArun P JohnyView Answer on Stackoverflow
Solution 2 - HtmlAncientSyntaxView Answer on Stackoverflow
Solution 3 - HtmlJon SchneiderView Answer on Stackoverflow
Solution 4 - HtmlJohann MarxView Answer on Stackoverflow
Solution 5 - HtmlcmejetView Answer on Stackoverflow
Solution 6 - HtmlKarvanView Answer on Stackoverflow