Issue
I can't make a navbarmenu fit in the web position, I tried so many times but didn't work for me. Could someone help me please.
How can i make this navbar in this position : https://prnt.sc/pMAPPMmneH7x navbar in the photo.
In this case i used : display: flex;
align-items: center;
justify-content: space-between;
Solution
Here is the way I would do it ( If you have any questions, feel free to ask! ) :
/* Bright Colors are for debug !!! */
/* Setting font and variable that will be used everywhere */
:root {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
--dev-color: #5faedb;
}
/* Making sure the page cannot scroll left to right, only top to bottom */
body {
overflow-x: hidden;
overflow-y: auto;
}
/* Styling the navigation bar to contain 3 elements, .branding, .links, and .auth, */
.nav {
display: flex;
align-items: center;
justify-content: space-between;
flex-direction: row;
width: 100%;
height: 50px;
top: 0;
left: 0;
background: var(--dev-color);
position: fixed;
}
/* Styling container where logo is stored and styled */
.nav>.branding {
margin: 0 0 0 20px;
height: 100%;
}
.nav>.branding>a,
.nav>.branding>a>img {
display: flex;
align-items: center;
justify-content: center;
width: auto;
height: 100%;
}
/* Un-Ordered list of links ( Navigation ) */
.nav>.links {
display: flex;
align-items: center;
justify-content: center;
flex-direction: row;
list-style: none;
margin: 0 10px 0 10px;
padding: 0;
height: 100%;
}
.nav>.links>li {
margin: 10px;
}
.nav>.links>li>a {
font-weight: 600;
color: white;
text-decoration: none;
position: relative;
}
.nav>.links>li>a::after {
content: "";
width: 100%;
height: 1px;
left: 0;
bottom: -5px;
transform: scaleX(0);
background: white;
position: absolute;
}
.nav>.links>li>a:hover::after {
transform: scaleX(1);
}
/* Authentication links ( Usually Sign in and Sign up ) */
.nav>.auth {
display: flex;
align-items: center;
justify-content: center;
margin: 0 10px 0 0;
height: 100%;
font-weight: 600;
}
.nav>.auth>a {
color: white;
padding: 10px 20px;
background: rgba(255, 255, 255, 0.5);
border-radius: 20px;
text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Your Title</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<nav class="nav" id="nav">
<span class="branding">
<!-- Logo -->
<a href="#">
<img
src="https://www.kadencewp.com/wp-content/uploads/2020/10/alogo-1.png"
alt="Brand Logo"
/>
</a>
</span>
<ul class="links">
<!-- Links inside of navigation bar -->
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
<li><a href="#">Placeholder</a></li>
</ul>
<!-- Authentication Links -->
<span class="auth"><a href="#" class="signup">Sign Up</a></span>
</nav>
</body>
</html>
Answered By - Caden Finkelstein
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.