Bootstrap popover hides line breaks
Solution 1:
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:
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:
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:
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:
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;
}