Bootstrap popover hides line breaks

眉间皱痕 提交于 2019-12-02 19:58:33
Arun P Johny

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

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

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

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;    
}

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!

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;
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!