I’m working on rendering markdown for a project, and I’m facing an issue with styling nested lists using CSS. In the example below, you can see that there are unwanted spaces between the elements in each <li>
item, which affects the alignment of the list indicators (like decimal or disc) with the content.
Here’s the HTML structure I’m using:
<h4 id="for-apache">For Apache:</h4>
<ol>
<li>
<p><strong>Create a Virtual Host:</strong></p>
<ul>
<li>Open your Apache configuration file (usually found in <code>/etc/httpd/conf/httpd.conf</code> or <code>/etc/apache2/sites-available/</code>).</li>
<li>Add the following configuration:</li>
</ul>
<pre>
<code>
<VirtualHost *:80>
ServerName chatbot.example.com
Redirect / http://example.com/chatbot
</VirtualHost>
</code>
</pre>
</li>
</ol>
Here’s a screenshot of the issue:
I want to remove the unexpected spaces between the list items without affecting the list type indicators. How can I adjust the CSS to eliminate these unwanted spaces?
2
Answers
Have you tried removing the different margins and padding in your CSS?
If you haven’t, here is what I think could help you:
A
<p>
element is what is known as a "block-level" element. What’s that mean? MDN can tell you more than you’d ever want to know, but TL;DR it wants to be on a line all by itself at 100% width. That’s why it’s not sitting next to the<li>
marker.I’d recommend just removing that wrapping element entirely. If you need something to target with CSS, you can use
<p>
‘s inline cousin,<span>
, although you already have<strong>
.…And as an academic note, this would also fix the space if you were inclined to keep the tag:
li > p { display: inline-block; }