Bootstrap popover hides line breaks

后端 未结 6 1006
野趣味
野趣味 2020-12-24 10:44

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



        
相关标签:
6条回答
  • 2020-12-24 10:58

    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!

    0 讨论(0)
  • 2020-12-24 11:07

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

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

    0 讨论(0)
  • 2020-12-24 11:07

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

    0 讨论(0)
  • 2020-12-24 11:10

    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

    0 讨论(0)
  • 2020-12-24 11:11

    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;    
    }
    
    0 讨论(0)
  • 2020-12-24 11:20

    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;
    }
    
    0 讨论(0)
提交回复
热议问题