如何将项目定位在Navbar中?

发布于 2025-02-02 13:01:10 字数 1911 浏览 3 评论 0原文

这可能非常简单,但我认为获得一些帮助,而不是在我能够上班之前玩2-3个小时,这将变得更简单。我有一个导航栏,我希望搜索栏出现在徽标旁边,该徽标旁边为我的设计及其使用Flex盒对齐。我已经尝试了一些目前不合作的事情。这是示例和代码:

”在此处输入图像描述”

vs我现在拥有的内容。

代码:

    <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:

enter image description here

vs What I have now.
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生戏 2025-02-09 13:01:10

尝试将锚标签包裹并形成DIV,并为DIV提供行列的弹性和挠性方向。

#logo-div {
  display: flex;
  flex-direction: column;
  align-items: center;
}
<div id="logo-div">
  <a href="http://" class="nav-branding">TravelSite</a>
  <form id="form">
    <input type="search" id="query" name="q" placeholder="Search...">
    <button>Search</button>
</div>

try wrapping the anchor tag and form in a div and giving the div a display of flex and flex direction of row.

#logo-div {
  display: flex;
  flex-direction: column;
  align-items: center;
}
<div id="logo-div">
  <a href="http://" class="nav-branding">TravelSite</a>
  <form id="form">
    <input type="search" id="query" name="q" placeholder="Search...">
    <button>Search</button>
</div>

随梦而飞# 2025-02-09 13:01:10

我建议的方法是使用将它们视为“盒子”的父级标签,然后样式的内容。

header {
  border: 1px solid red;
}

nav {
  border: 2px solid yellow;
  display: flex;
}

.logo-and-search {
  border: 2px solid purple;
  display: flex;
  gap: 20px;
}

.links {
  border: 2px solid purple;
  display: flex;
  gap: 10px;
}
<!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" />
  <link rel="stylesheet" href="style.css" />
  <title>Static Template</title>
</head>
<header>
  <nav>
    <div class="logo-and-search">
      <a href="http://" class="nav-branding">TravelSite</a>
      <form id="form">
        <input type="search" id="query" name="q" placeholder="Search..." />
        <button>Search</button>
      </form>
    </div>
    <div class="links">
      <a href="http://">Destinations</a>
      <a href="http://">Blog</a>
      <a href="http://">About</a>
      <a href="http://">Contact</a>
    </div>
  </nav>
</header>

</html>

codesandbox

My suggested approach is by working on parent tags thinking them as "boxes", then style their content.

header {
  border: 1px solid red;
}

nav {
  border: 2px solid yellow;
  display: flex;
}

.logo-and-search {
  border: 2px solid purple;
  display: flex;
  gap: 20px;
}

.links {
  border: 2px solid purple;
  display: flex;
  gap: 10px;
}
<!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" />
  <link rel="stylesheet" href="style.css" />
  <title>Static Template</title>
</head>
<header>
  <nav>
    <div class="logo-and-search">
      <a href="http://" class="nav-branding">TravelSite</a>
      <form id="form">
        <input type="search" id="query" name="q" placeholder="Search..." />
        <button>Search</button>
      </form>
    </div>
    <div class="links">
      <a href="http://">Destinations</a>
      <a href="http://">Blog</a>
      <a href="http://">About</a>
      <a href="http://">Contact</a>
    </div>
  </nav>
</header>

</html>

CodeSandbox

小草泠泠 2025-02-09 13:01:10

您可以在&lt; nav&gt;内使用2个DIV,第一div将具有徽标,而搜索栏则将保留在

<!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" />
    <link rel="stylesheet" href="style.css" />
    <title>Static Template</title>
</head>
<header>
    <nav class="nav-links">
        <div class="left-content">
            <a href="http://" class="nav-branding">TravelSite</a>
            <form id="form">
                <input type="search" id="query" name="q" placeholder="Search...">
                <button>Search</button>
            </form>
        </div>
        <div class="right-content">
            <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>
        </div>
    </nav>
</header>

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>

<!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" />
    <link rel="stylesheet" href="style.css" />
    <title>Static Template</title>
</head>
<header>
    <nav class="nav-links">
        <div class="left-content">
            <a href="http://" class="nav-branding">TravelSite</a>
            <form id="form">
                <input type="search" id="query" name="q" placeholder="Search...">
                <button>Search</button>
            </form>
        </div>
        <div class="right-content">
            <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>
        </div>
    </nav>
</header>

on css the class .nav-links will make a gap between div.lef-content and div.right-content

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文