How to preserve line breaks in block?

后端 未结 3 1971
Happy的楠姐
Happy的楠姐 2020-12-01 18:02

I have some code samples which I want to publish in an HTML document. I\'m wrapping them with , tags but I\'d like them to be styled such that line

相关标签:
3条回答
  • 2020-12-01 18:27

    You could try using the CSS suggested here: http://ajaxian.com/archives/wrapping-the-pre-tag

    0 讨论(0)
  • 2020-12-01 18:33

    Check your doctype is valid and on the first line. Maybe it's slipping into quirks mode?

    0 讨论(0)
  • 2020-12-01 18:33

    Are you sure you're not doing something wrong? This code works for me on IE7:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
      <style type="text/css">
      code { white-space: pre; }
      </style>
    </head>
    <body>
      <code>
          function() {
              alert('yay');
          }
      </code>
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题