I have a list that contains 3 items. However, it has a little margin on its left side, I want it to disappear.
Here is my code:
This should work
ul {
display: inline;
list-style: none;
margin: 0px;
padding: 0px;
}
li{
display: inline;
}
<ul>
<li>I have margin space on my left side</li>
<li>List 2</li>
<li>List 3</li>
</ul>
<p>
Hi! I am a text without any margin!
</p>
Just set padding of your ul
to 0. Here's a snippet:
ul {
padding: 0;
}
ul li {
display: inline;
list-style: none;
}
<ul>
<li>Hey, now I don't have extra space on my left side!</li>
<li>List 2</li>
<li>List 3</li>
</ul>
<p>
Hi! I am a text without any margin!
</p>
You can set a global style rule, like so:
* {padding:0; margin:0;}
Use this code on top of your style sheet. It will reset default margin and padding for all elements.
Hope it will work.
It's the browser default
and you have to reset
the padding
for the ul
element.
If you look at the chrome dev tool
, you can see the browser defaults as below.
Code
ul {
padding-left: 0;
}
ul li {
display: inline;
list-style: none;
margin-left: 0;
}
<ul>
<li>I have margin space on my left side</li>
<li>List 2</li>
<li>List 3</li>
</ul>
<p>
Hi! I am a text without any margin!
</p>
You need to reset ul
margin
and padding
to zero (0
)
ul {
padding: 0;
margin: 0;
}
ul li {
display: inline;
list-style: none;
}
<ul>
<li>I have margin space on my left side</li>
<li>List 2</li>
<li>List 3</li>
</ul>
<p>
Hi! I am a text without any margin!
</p>