Home  >  Q&A  >  body text

Copy: How to add margins to items

<p>I have an unordered list and I set the style to none, which creates the default indented space. <br /><br />My understanding of margins and padding is that margins are the outer space of an element, so I tried to use margin: 0 to fix the gap, but it didn't work. When I use padding: 0, it removes the indented space from the li items. <br /><br />Now I'm confused why there is padding and not margin in this case. </p><p><br /></p> <p><br /></p> <pre class="brush:css;toolbar:false;">ul { list-style-type: none; padding: 0px; }</pre> <pre class="brush:html;toolbar:false;"><ul> <li> Linkedin </li> </ul></pre> <p><br /></p>
P粉037215587P粉037215587464 days ago459

reply all(1)I'll reply

  • P粉511757848

    P粉5117578482023-08-03 11:14:58

    The default setting of the browser is to add some padding to the UI instead of margin. So using padding: 0px will override the browser's default value.

    Look at the Computed tab on the right, it shows a list of browser styles padding-left: 40px;


    ul.no-padding {
      list-style-type: none;
      padding: 0px;
    }
    
    ul.no-margin {
      list-style-type: none;
      margin: 0px;
    }
    <ul>
      <li>
        Linkedin
      </li>
    </ul>
    
    <ul class="no-margin">
      <li>
        Linkedin
      </li>
    </ul>
    
    <ul class="no-padding">
      <li>
        Linkedin
      </li>
    </ul>

    reply
    0
  • Cancelreply