cssmarginpadding

Why is CSS 'padding' creating a margin in my element?


I have a 'ul' with a width of 100%, but when I put 'padding' in it, a right margin appears. Why is it happening? The code is below.

nav ul {
  list-style: none;
  text-align: center;
  background-color: rgb(90, 32, 102);
  line-height: 3.125em;
  position: relative;
  right: 38px;
  width: 100%;
  padding: 1em 0;
}
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Products</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>


Solution

  • Withdrawn due to negative score, must be wrong? Idk.