I am trying to create a zebra striped code sample using HTML and CSS. However, when I run the code snippet below, it adds unwanted new lines and does not apply the styling properly when using the scroll bar. How can I resolve this issue?
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<style>
body {
max-width: 650px;
margin: 0 auto;
}
pre {
counter-reset: code-line;
overflow-x: auto;
}
code {
counter-increment: code-line;
display: block;
}
code::before {
content: counter(code-line) ": ";
}
code:nth-child(odd) {
background-color: #aaa;
}
</style>
<body>
<pre>
<code>Quisque quis congue lectus. Nullam ornare quis magna sit amet volutpat. Nam quis magna id ex venenatis rutrum.</code>
<code>Quisque quis congue lectus. Nullam ornare quis magna sit amet volutpat.</code>
<code>Quisque quis congue lectus.</code>
</pre>
</body>
</html>