I hope you are all doing well, I have this nav bar, which took me a very long time to figure out, how I could separate the padding from the logo and my "li" elements so I could have a nice centered menu. But I think I kinda have something working, but I like to do things the right way, does anyone has a better way to center all the "li" elements (Home, About...).
Because at this current time I have padding-left: 30em;
which give the feeling of the menu been centered, but is there a way to do it automaticlly ? I tried padding auto but that dosen't work.
Thank your for helping a young dev.
@media screen and (min-width: 780px) {
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
margin: 0;
min-height: 100vh;
}
ul {
list-style: none;
}
a, u {
text-decoration: none;
}
.header-menu {
background-color: grey;
padding: 1em 1em;
width: 100vw;
display: inline-flex;
align-items: center;
}
.header-flex, {
display: inline-flex;
align-items: center;
}
.logo {
cursor: pointer;
}
.main-nav {
cursor: pointer;
padding-left: 30em;
}
.main-nav li {
display: inline-block;
padding: 0em 1.2em;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="./css/home.css">
</head>
<body>
<header>
<div class="header-menu">
<h1 class="logo">Logo</h1>
<nav class="header-flex">
<ul class="main-nav">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
</header>
</body>
</html>
Thank for helping, How I solved the issue
@media screen and (min-width: 780px) {
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
margin: 0;
min-height: 100vh;
}
ul {
list-style: none;
}
a, u {
text-decoration: none;
}
.header-menu, .header-flex {
background-color: grey;
padding: 1em 1em;
width: 100vw;
display: inline-flex;
align-items: center;
}
.logo {
cursor: pointer;
}
.main-nav {
cursor: pointer;
margin: 0 auto;
}
.main-nav li {
display: inline-block;
padding: 0em 1.2em;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
}