Branco
Branco

Reputation: 47

Why is my navigation bar picture not moving properly?

So, I'm currently trying to make a Navigation bar for my website and it works just fine! but right now I'm stuck with this annoying picture that can't properly move.

Problem: I want the navigation picture just a few pixels away from the side of the page but when I use padding-left I also move the navigation section but I want this to be centerd and the picture to be a few pixels from the left. Hope anybody could help me

body {
	margin: 0 0 0 0;
	padding: 0 0 0
	font: arial;
	}

nav {
	margin: 0;
	background-color: #595959;
	color: #ffffff;
	list-style: none;
	text-align: center;
	padding: 20px 0 20px 0;

	 }

nav > ul > li {
	display: inline-block;
	padding: 0 25px 0 50px;
		  }

nav > ul> li > a {
	text-decoration: none;
	color: white;
	font-family: Roboto;
			   }

nav > ul> li > a:hover {
		color: #c1c1c1
					}

nav > .logo > img {
	float: left;
	padding: 0 0 0 25px;

}
<!DOCTYPE html>
<html>
	
	<head>
		<title>Branco - Home</title>
		<meta charset="utf-8">
		<link rel="stylesheet" type="text/css" href="style.css">
		<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
	</head>

	<body>
		<nav>
			<div class="logo"> 
				<img src="http://ikbenbranco.nl/assets/icon.png" height="60px"> 


			</div>
				<ul>
					<li><a href="index.html">Home</a></li>
					<li><a href="about.html">About</a></li>
					<li><a href="contact.html">Contact</a></li>
				</ul>
			</nav>

	</body>

</html>

Thanks, Branco

Upvotes: 2

Views: 360

Answers (2)

Amiratak88
Amiratak88

Reputation: 1539

So in this case u have to position it absolutely if u don't want it to affect the other elements in the nav bar.

here's the css:

body {
    margin: 0;
    padding: 0;
    font: arial;
}

nav {
    margin: 0;
    background-color: #595959;
    color: #ffffff;
    list-style: none;
    text-align: center;
    padding: 20px 0 20px 0;
  position: relative;
}

nav > ul > li {
    display: inline-block;
    padding: 0 25px 0 50px;
}

nav > ul> li > a {
    text-decoration: none;
    color: white;
    font-family: Roboto;
               }

nav > ul> li > a:hover {
        color: #c1c1c1
                    }

nav > .logo > img {
  position: absolute;
  top:50%;
  transform: translateY(-50%);
  left: 10px;
}

Upvotes: 2

nara92
nara92

Reputation: 153

Try to replace your img styles for this. Remove your float and padding lines. Add a position absolute. Then, also add a left and a top properties. Adjust the values as you wish the picture to be positioned. This should fix your issue.

Upvotes: 0

Related Questions