如何将项目定位在Navbar中?
这可能非常简单,但我认为获得一些帮助,而不是在我能够上班之前玩2-3个小时,这将变得更简单。我有一个导航栏,我希望搜索栏出现在徽标旁边,该徽标旁边为我的设计及其使用Flex盒对齐。我已经尝试了一些目前不合作的事情。这是示例和代码:
代码:
<header>
<nav class="nav-links">
<a href="http://" class="nav-branding">TravelSite</a>
<form id="form">
<input type="search" id="query" name="q" placeholder="Search...">
<button>Search</button>
</form>
<ul>
<li><a href="http://">Destinations</a></li>
<li><a href="http://">Blog</a></li>
<li><a href="http://">About</a></li>
<li><a href="http://">Contact</a></li>
</ul>
</nav>
</header>
@import url('https://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,800,900&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
.nav-links{
position: fixed;
display: flex;
justify-content: space-between;
margin-right: 40px;
padding: 30px;
background: lightblue;
width: 100%;
}
nav:nth-child(2){
left: 350px;
}
.nav-branding{
margin-left: 40px;
}
.form{
display: flex;
justify-content: left;
}
.nav-search{
left: 300px;
}
nav ul{
display: flex;
list-style-type: none;
justify-content: space-evenly;
}
This is probably super simple but I figured it would just be simpler to get some help instead of playing with for 2-3 hours before I can get it to work. I have a nav bar and I want the search bar to appear next to the logo which is left aligned for my design and its using flex box. I've tried a few things its not cooperating currently. Here's the example and code:
Code:
<header>
<nav class="nav-links">
<a href="http://" class="nav-branding">TravelSite</a>
<form id="form">
<input type="search" id="query" name="q" placeholder="Search...">
<button>Search</button>
</form>
<ul>
<li><a href="http://">Destinations</a></li>
<li><a href="http://">Blog</a></li>
<li><a href="http://">About</a></li>
<li><a href="http://">Contact</a></li>
</ul>
</nav>
</header>
@import url('https://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,800,900&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
.nav-links{
position: fixed;
display: flex;
justify-content: space-between;
margin-right: 40px;
padding: 30px;
background: lightblue;
width: 100%;
}
nav:nth-child(2){
left: 350px;
}
.nav-branding{
margin-left: 40px;
}
.form{
display: flex;
justify-content: left;
}
.nav-search{
left: 300px;
}
nav ul{
display: flex;
list-style-type: none;
justify-content: space-evenly;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将锚标签包裹并形成DIV,并为DIV提供行列的弹性和挠性方向。
try wrapping the anchor tag and form in a div and giving the div a display of flex and flex direction of row.
我建议的方法是使用将它们视为“盒子”的父级标签,然后样式的内容。
codesandbox
My suggested approach is by working on parent tags thinking them as "boxes", then style their content.
CodeSandbox
您可以在
&lt; nav&gt;
内使用2个DIV,第一div将具有徽标,而搜索栏则将保留在CSS上的
&lt; ul&gt;
班级.nav-links将在Div.lef-content和Div.Right-content之间差距you can use 2 divs inside the
<nav>
, the first div will have the logo and the search-bar, second div will stay with<ul>
on css the class .nav-links will make a gap between div.lef-content and div.right-content