提问人:florin broqi 提问时间:11/16/2023 更新时间:11/16/2023 访问量:55
如何将导航栏置于此位置 [关闭]
How to put navbar in this position [closed]
问:
我无法使导航栏菜单适合 Web 位置,我尝试了很多次,但对我不起作用。 有人可以帮我吗?
我怎样才能在这个位置制作这个导航栏:https://prnt.sc/pMAPPMmneH7x 照片中的导航栏。
在这种情况下,我使用了:display:flex;
align-items:居中;
justify-content:中间的空格;
答:
0赞
Fito
11/16/2023
#1
您可以执行以下操作:
在您的代码中创建 3 个代码,然后使用 flexbox。<header>
例如:
header {
display:flex;
justify-content: space-between;
}
<header>
<a>My Logo</a>
<nav>
<a>Link 1</a>
<a>Link 2</a>
<a>Link 3</a>
</nav>
<button>Sign Up</button>
</header>
现在它应该可以工作了!
评论
0赞
Fito
11/16/2023
是的,很抱歉,flex 属性也可以在那里工作,我刚刚编辑了答案。
0赞
Caden Finkelstein
11/16/2023
#2
这是我的做法(如果您有任何问题,请随时提问!
/* 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>
评论
0赞
florin broqi
11/20/2023
非常感谢,这对我帮助很大。
评论