为什么我的搜索栏没有向右对齐?

发布于 2025-01-10 07:20:15 字数 1217 浏览 1 评论 0原文

我正在使用引导程序创建一个搜索栏,问题是我希望它与导航栏的右侧对齐,而不是留在左侧。问题如下:

在此处输入图像描述

仅供参考,搜索文本与徽标重叠,但我们不需要担心这一点。问题是我希望搜索栏位于屏幕的右侧。顺便说一句,导航栏元素的父级是容器流体,但不是行

为什么它没有与导航栏的右侧对齐?

#search-bar {
  background: #FFFFFF;
  float: right;
  height: 28px;
  width: 32%;
  margin-right: 40px
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<nav class="navbar col-12"> <img class="navbar-brand" src="https://via.placeholder.com/50" alt="Ventr Logo" width="100">
  <input class="form-control" type="text" placeholder="Search" aria-label="Search" id="search-bar" align="right">
</nav>

I am creating a search bar with bootstrap and the problem is that I want it to align to the right side of the nav bar, instead it is staying on the left. Here is the issue:

enter image description here

FYI, the search text is being overlapped by the logo, but we don't need to worry about that. The problem is I want the search bar to be on the right side of the screen. By the way, the navbar element is parented to a container-fluid, but not a row.

Why is it not aligned to the right side of the navbar?

#search-bar {
  background: #FFFFFF;
  float: right;
  height: 28px;
  width: 32%;
  margin-right: 40px
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<nav class="navbar col-12"> <img class="navbar-brand" src="https://via.placeholder.com/50" alt="Ventr Logo" width="100">
  <input class="form-control" type="text" placeholder="Search" aria-label="Search" id="search-bar" align="right">
</nav>

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

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

发布评论

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

评论(2

万劫不复 2025-01-17 07:20:15

已解决,Bootstrap 对此不是必需的,我只需使用常规 HTMLCSS 即可。

Solved, Bootstrap is not necessary for this, I'm just going to use regular HTML and CSS.

蓝眼泪 2025-01-17 07:20:15

去看看预先构建的引导导航。在大多数情况下,它们是我所需要的基础。您可以根据需要自定义它们。提供了代码,并且搜索栏从一开始就向右对齐。

https://getbootstrap.com/docs/5.0/components/navbar/

Go take a look at the bootstrap navigations that are pre-built. In most cases, they've been the base of what I needed. You can customise them as much as you really want. The code is provided and the search bars are aligned to the right from the start.

https://getbootstrap.com/docs/5.0/components/navbar/

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