如何将导航链接到右边的同时,将文本放在徽标旁边?

发布于 2025-02-07 12:44:35 字数 1504 浏览 2 评论 0原文

这是CSS的新手,我一直在从事一个练习项目,但无法做标题所说的。

我尝试了我在许多视频中看到的边缘权利:自动方法,它起作用,但它仅以标题为中心。

这是一些代码:

.logo {
  cursor: pointer;
  margin-right: auto;
  margin-left: 1.5rem;
  height: 3rem;
  width: auto;
}

.title {
  text-transform: capitalize;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.8rem;
  font-weight: bold;
  margin-right: auto;
}

header {
  position: fixed;
  z-index: 100;
  width: 100%;
  height: 4rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.nav_links {
  list-style: none;
}

.nav_links li {
  display: inline-block;
  padding: 0 1.5rem 0 1rem;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.2rem;
}
<header>
  <img class="logo" src="./Images/ic-logo.svg" alt="logo">
  <div class="title">
    <span class="title1">COLMAR</span>
    <span class="title2">ACADEMY</span>
  </div>
  <nav>
    <ul class="nav_links">
      <li><a href="#">On Campus</a></li>
      <li><a href="#">Online</a></li>
      <li><a href="#">For companies</a></li>
      <li><a href="#">Sign in</a></li>
    </ul>
  </nav>
</header>

我试图将标题移到徽标旁边,同时将导航栏链接到右侧。

任何帮助/指针都非常感谢。

This I'm new to CSS and I have been working on a practice project, but have not been able to do what title says.

I have tried the margin-right: auto method that I've seen in numerous videos and it works, but it only centers the title.

Here's some of the code:

.logo {
  cursor: pointer;
  margin-right: auto;
  margin-left: 1.5rem;
  height: 3rem;
  width: auto;
}

.title {
  text-transform: capitalize;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.8rem;
  font-weight: bold;
  margin-right: auto;
}

header {
  position: fixed;
  z-index: 100;
  width: 100%;
  height: 4rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.nav_links {
  list-style: none;
}

.nav_links li {
  display: inline-block;
  padding: 0 1.5rem 0 1rem;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.2rem;
}
<header>
  <img class="logo" src="./Images/ic-logo.svg" alt="logo">
  <div class="title">
    <span class="title1">COLMAR</span>
    <span class="title2">ACADEMY</span>
  </div>
  <nav>
    <ul class="nav_links">
      <li><a href="#">On Campus</a></li>
      <li><a href="#">Online</a></li>
      <li><a href="#">For companies</a></li>
      <li><a href="#">Sign in</a></li>
    </ul>
  </nav>
</header>

I'm trying to move the title next to the logo, while keeping the nav bar links to the right.

Any help/pointers are really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

无法回应 2025-02-14 12:44:35

这样做:

  1. 标题不应具有合理性:flex-end;
  2. 徽标不需要rain> rain-right:auto。标题具有保证权利:auto;

阅读内联注释。

.logo {
  cursor: pointer;
  /*  NEW */
  /* margin-right: auto; */
  margin-left: 1.5rem;
  height: 3rem;
  width: auto;
}

.title {
  text-transform: capitalize;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.8rem;
  font-weight: bold;
  margin-right: auto;
}

header {
  position: fixed;
  z-index: 100;
  width: 100%;
  height: 4rem;
  display: flex;
  /*  NEW */
  /* justify-content: flex-end;  */
  align-items: center;
}

.nav_links {
  list-style: none;
}

.nav_links li {
  display: inline-block;
  padding: 0 1.5rem 0 1rem;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.2rem;
}
<header>
  <img class="logo" src="./Images/ic-logo.svg" alt="logo">
  <div class="title">
    <span class="title1">COLMAR</span>
    <span class="title2">ACADEMY</span>
  </div>
  <nav>
    <ul class="nav_links">
      <li><a href="#">On Campus</a></li>
      <li><a href="#">Online</a></li>
      <li><a href="#">For companies</a></li>
      <li><a href="#">Sign in</a></li>
    </ul>
  </nav>
</header>

Do this:

  1. Header should not have justify-content: flex-end;
  2. The logo does not need margin-right:auto either. It is enoug that the title has margin-right: auto;

Read the inline comments.

.logo {
  cursor: pointer;
  /*  NEW */
  /* margin-right: auto; */
  margin-left: 1.5rem;
  height: 3rem;
  width: auto;
}

.title {
  text-transform: capitalize;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.8rem;
  font-weight: bold;
  margin-right: auto;
}

header {
  position: fixed;
  z-index: 100;
  width: 100%;
  height: 4rem;
  display: flex;
  /*  NEW */
  /* justify-content: flex-end;  */
  align-items: center;
}

.nav_links {
  list-style: none;
}

.nav_links li {
  display: inline-block;
  padding: 0 1.5rem 0 1rem;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 1.2rem;
}
<header>
  <img class="logo" src="./Images/ic-logo.svg" alt="logo">
  <div class="title">
    <span class="title1">COLMAR</span>
    <span class="title2">ACADEMY</span>
  </div>
  <nav>
    <ul class="nav_links">
      <li><a href="#">On Campus</a></li>
      <li><a href="#">Online</a></li>
      <li><a href="#">For companies</a></li>
      <li><a href="#">Sign in</a></li>
    </ul>
  </nav>
</header>

找个人就嫁了吧 2025-02-14 12:44:35

不确定您在这里要做什么,图纸或表示形式将特别有用。但是我有两种可以用来解决此问题的方法。

  1. 使用Flex-Box:

制作一个将弹性盒像这样包裹徽标的弹性盒:

 <div style="display: flex; flex-direction: row;">
      <img class="logo" src="./Images/ic-logo.svg"alt="logo">
      <div class="title">
           <span class="title1">COLMAR</span>
           <span class="title2">ACADEMY</span>
      </div>
 </div>

并使用导航栏做同样的事情:)

  1. 只需从徽标中删除保证金权利,它似乎可以在浏览器中工作。

Not sure what you are trying to do here and a drawing or a representation would be particularly helpful. But I've got two ways that you can use to fix this.

  1. Use flex-boxes:

Make a flex box that will wrap the logo like so:

 <div style="display: flex; flex-direction: row;">
      <img class="logo" src="./Images/ic-logo.svg"alt="logo">
      <div class="title">
           <span class="title1">COLMAR</span>
           <span class="title2">ACADEMY</span>
      </div>
 </div>

And do the same thing with your navigation bar :)

  1. Just remove margin-right from the logo and it seemed to work in browser just fine.
┈┾☆殇 2025-02-14 12:44:35

使用您的HTML结构,您可以使用下面的CSS完成此操作。我剥离了您的样式,因此您只能看到完成您要求的准确的需要的内容。

header {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}

.logo {
  flex-shrink: 1;
  margin-right: 8px;
}

.title {
  flex-grow: 1;
}

.nav_links {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}

.nav_links li {
  margin-left: 8px;
}
<header>
  <img class="logo" src="./Images/ic-logo.svg" alt="logo">
  <div class="title">
    <span class="title1">COLMAR</span>
    <span class="title2">ACADEMY</span>
  </div>
  <nav>
    <ul class="nav_links">
      <li><a href="#">On Campus</a></li>
      <li><a href="#">Online</a></li>
      <li><a href="#">For companies</a></li>
      <li><a href="#">Sign in</a></li>
    </ul>
  </nav>
</header>

Using your HTML structure you can accomplish this with the css below. I stripped away your styling so you can see only what is needed to accomplish exactly what you are asking for.

header {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}

.logo {
  flex-shrink: 1;
  margin-right: 8px;
}

.title {
  flex-grow: 1;
}

.nav_links {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}

.nav_links li {
  margin-left: 8px;
}
<header>
  <img class="logo" src="./Images/ic-logo.svg" alt="logo">
  <div class="title">
    <span class="title1">COLMAR</span>
    <span class="title2">ACADEMY</span>
  </div>
  <nav>
    <ul class="nav_links">
      <li><a href="#">On Campus</a></li>
      <li><a href="#">Online</a></li>
      <li><a href="#">For companies</a></li>
      <li><a href="#">Sign in</a></li>
    </ul>
  </nav>
</header>

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