HTML code so far
<div class="code-container">
<div class="line-numbers">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
<pre>
<code>
<div id="example">
<p>This is example text</p>
</div>
</code>
</pre>
</div>
<p>JS</p>
<div class="code-container">
<div class="line-numbers">
<span>1</span>
</div>
<pre>
<code>
const ExampleVar = document.getElementById("example");
</code>
</pre>
</div>
and my CSS:
.code-container {
display: flex;
background-color: #f4f4f4;
border-radius: 5px;
overflow-x: auto;
font-family: monospace;
color: red;
}
.line-numbers {
padding: 10px 5px;
text-align: right;
color: #888;
user-select: none;
background-color: #eaeaea;
}
.line-numbers span {
display: block;
line-height: 1.5em;
}
pre {
margin: 0;
padding: 10px;
line-height: 1.5em;
overflow-x: auto;
}
code {
display: block;
white-space: pre;
}
and this is the product:
Notice how the numbers are unaligned? How do I fix this? thanks!