0

I have created a nested list in html.

Why does setting margin: 0 using the *{} selector remove the list indention but not if I use the body selector?

body {
  padding: 0px;
}
<ul>
  <li>Home</li>
  <li>About</li>
  <li>Resume
    <ul>
      <li>Experience</li>
      <li>Skills</li>
      <li>Portfolio</li>
    </ul>
  </li>
  <li>Interests
    <ul>Photography</ul>
    <ul>Favourites</ul>
  </li>
</ul>
Etheryte
  • 24,589
  • 11
  • 71
  • 116
Pete Smyth
  • 67
  • 7
  • 1
    Because `*` represent all element, and `body{}` just the body. The padding is in the `
      ` element
    – Roy Bogado Apr 18 '19 at 09:04
  • What @Roy said, plus the fact that `padding` is [not an inherited property](https://stackoverflow.com/questions/5612302/which-css-properties-are-inherited). The padding you set for the `body` element applies only to that element, not to its children. – Thomas Apr 18 '19 at 09:05

1 Answers1

1

The asterisk * means all, so when you put a property in (all) it basically styles all the elements in your HTML body

But when you choose only to style the body you don't change anything's style but body

You can read the answers here for more details

xTrimy
  • 804
  • 9
  • 23