Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move all li elements to the left side of the <ul> element?

I want to move all li elements to the left side of the ul element. It looks like the first li element has a left margin >0 which I don't understand.

Do you know how I can fix this?

The ultimate goal is: the first li element #music and #email element in the footer have the same left margin of 70px (same distance from the left border).

html,
body {
  margin: 0;
  text-align: center;
}

header {
  overflow: hidden
}

nav {
  overflow: hidden;
  display: inline-block;
  float: left;
  margin-left: 70px;
}

nav li {
  margin-right: 70px;
  float: left;
}

nav ul {
  list-style: none;
  overflow: hidden
}

#email {
  float: left;
  padding: 25px 0px;
  margin-left: 70px;
}

.wrapper {
  border: 2px solid green;
}

#menu2 {
  float: right;
  margin-right: 70px;
  border: 2px solid green;
}

ul {
  margin-top: 0px;
  margin-bottom: 0px;
}
<div class="wrapper">
  <header>
    <nav id="menu">
      <ul>
        <li id="music">
          <a href="#"><img src="gfx/music40.gif"></a>
        </li>
        <li id="film">
          <a href="#"><img src="gfx/film40.gif"></a>
        </li>
        <li id="visual">
          <a href="#"><img src="gfx/visual40.gif"></a>
        </li>
        <li id="media">
          <a href="#"><img src="gfx/media40.gif"></a>
        </li>
      </ul>
    </nav>
    <div id="menu2">
      <a id="logo" href="index.html"><img src="gfx/tobera40.gif" alt="logo" class="logo"></a>
    </div>
  </header>

  <div id="main">
    <img src="gfx/banner40.jpg">
  </div>


  <footer>
    <div id="email">
      <img src="email.jpg">
    </div>
  </footer>
</div>
like image 960
Hallonka Avatar asked Jul 11 '18 21:07

Hallonka


2 Answers

The padding on the ul pushes your li items over to the right. Since #email and nav are both indented 70px the only difference is the padding on the ul. Try adding:

ul {
    padding: 0;
}
like image 60
Jensei Avatar answered Oct 14 '22 14:10

Jensei


You can add padding: 0 to the ul element to force it to stick to the left border of the parent nav element.

like image 24
Samuryte Avatar answered Oct 14 '22 14:10

Samuryte