简体   繁体   中英

Code block spacing within an html list item

I am nesting code in an ordered list as a set of instructions for some teammates. However, when I nest a code block within a list item, the spacing is totally off. The code in my code block starts halfway through width of the page. Here is some sample code:

<html>
<head>Test</head>
<body>
    <ol>
    <li> This is a test list item.
        <pre>
        <code>
            def my_function(a):
                return a
        </code>
        </pre>
    </li>
    <li>Element 2
    </li>
</body>
</html>

It's because you're indenting the code in the markup, try this

<ol>
  <li> This is a test list item.
    <pre>
    <code>
 def my_function(a):
   return a
    </code>
    </pre>
  </li>
  <li>Element 2
  </li>
</ol>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM