I want to create a simple navbar and I want it centered. It works, but when I add an image above the ul, the list is not centered anymore and I don't know why. I centered the header element with justify-content center.
To center the logo, I changed the margin left and right to auto and put a width of 20% on it. It looks like something is wrong with the image but I'm not sure.
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap');
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
body{
font-family: "Montserrat",sans-serif;
font-weight: 500;
}
header{
display: flex;
padding: 25px 10%;
justify-content: center;
}
.logo{
display: block;
margin: 0 auto;
width: 20%;
}
.nav__links li{
display:inline;
padding: 0 15px;
}
.nav__links li a{
color:#000000;
text-decoration: none;
transition: 0.3s;
}
.nav__links li a:hover{
color: rgb(0, 0, 0,0.8);
}
<!DOCTYPE html>
<head>
<title>Navbar</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<nav>
<img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png"
alt="google">
<ul class="nav__links">
<li><a href="#">Plan your visit</a></li>
<li><a href="#">Exhibitions and events</a></li>
<li><a href="#">Art and artists</a></li>
<li><a href="#">Store</a></li>
</ul>
</nav>
</header>
</body>
</html>