Bootstrap popover hides line breaks

扶醉桌前 提交于 2019-12-03 06:28:34

问题


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....


回答1:


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

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




回答2:


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




回答3:


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



回答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!




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



回答6:


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



来源:https://stackoverflow.com/questions/14459691/bootstrap-popover-hides-line-breaks

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