evghenii turco
evghenii turco

Reputation: 43

How to move little image inside the menu?

How do I move the little arrow image which is inside <li>?

Here is the code:

body {
  margin: 0;
  padding: 0;
}
nav {
  width: 100%;
  background: #f1f1f1;
  padding: 5px;
}
nav ul {
  list-style-type: none;
}
nav ul li {
  display: inline-block;
}
nav ul li a img {
  max-width: 20px;
  height: auto;
  margin-left: 4px;
}
nav ul li a {
  color: #636363;
  padding: 10px;
  text-decoration: none;
}
nav ul li a:hover {
  color: #333;
  text-decoration: underline;
}
<!DOCTYPE html>

<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="css-1.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script type="text/javascript" src="javascript-1.js"></script>
  <title>Haircut</title>
</head>

<body>
  <header>
    <nav>
      <ul>
        <li><a href="#">News</a>
        </li>
        <li><a href="#">Delivery</a>
        </li>
        <li><a href="#">Destinations<img src="https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_keyboard_arrow_down_48px-128.png"></a>
        </li>
        <li><a href="#">Guaranties</a>
        </li>
        <li><a href="#">Contacts</a>
        </li>
      </ul>
    </nav>
  </header>



</body>

</html>

If I just add margin-top to the img element it moves all the ul down. That's not what I want. I want to move it a little bit down to align with the li items

Upvotes: 1

Views: 80

Answers (2)

davide andreazzini
davide andreazzini

Reputation: 239

You can set the image as position absolute.

nav ul li a img {
  position:absolute;
  max-width: 20px;
  height: auto;
  margin-left: 4px;
}

Then you can position it using the top property, not beautiful but works

http://jsbin.com/goyozo/edit?html,css

Upvotes: 0

Joseph Marikle
Joseph Marikle

Reputation: 78580

vertical-align: middle; Might be what you need.

body {
  margin: 0;
  padding: 0;
}
nav {
  width: 100%;
  background: #f1f1f1;
  padding: 5px;
}
nav ul {
  list-style-type: none;
}
nav ul li {
  display: inline-block;
}
nav ul li a img {
  max-width: 20px;
  height: auto;
  margin-left: 4px;
  vertical-align: middle;
}
nav ul li a {
  color: #636363;
  padding: 10px;
  text-decoration: none;
}
nav ul li a:hover {
  color: #333;
  text-decoration: underline;
}
<!DOCTYPE html>

<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="css-1.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script type="text/javascript" src="javascript-1.js"></script>
  <title>Haircut</title>
</head>

<body>
  <header>
    <nav>
      <ul>
        <li><a href="#">News</a>
        </li>
        <li><a href="#">Delivery</a>
        </li>
        <li><a href="#">Destinations<img src="https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_keyboard_arrow_down_48px-128.png"></a>
        </li>
        <li><a href="#">Guaranties</a>
        </li>
        <li><a href="#">Contacts</a>
        </li>
      </ul>
    </nav>
  </header>



</body>

</html>

Upvotes: 3

Related Questions