html - 我想将搜索栏对齐到最右边

标签 html css alignment

我试图在导航栏中对齐搜索栏,但我所有的努力都是徒劳的。

我没有在此处包含我的整个导航栏代码,仅在 div 容器中包含我的导航栏内的搜索栏。

.search {
      width: 100%;
      position: relative;
      display: flex;
    }

    .searchTerm {
      width: 100%;
      border: 3px solid #00B4CC;
      border-right: none;
      padding: 5px;
      height: 20px;
      border-radius: 5px 0 0 5px;
      outline: none;
      color: #9DBFAF;
    }

    .searchTerm:focus{
      color: #00B4CC;
    }

    .searchButton {
      width: 20px;
      height: 20px;
      border: 1px solid #00B4CC;
      background: #00B4CC;
      text-align: center;
      color: #fff;
      border-radius: 0 5px 5px 0;
      cursor: pointer;
      font-size: 20px;
    }

    .wrap{
      width: 30%;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    .topnav-right {
      float: right;

    }
<div class="topnav-right">
      <div class="wrap">
         <div class="search">
            <input type="text" class="searchTerm" placeholder="What are you looking for?">
            <button type="submit" class="searchButton">
              <i class="fa fa-search"></i>
           </button>
         </div>
      </div>
      </div>    

我的做法是否正确?

最佳答案

更改 CSS

.wrap{
      width: 30%;
      position: absolute;
      top: 50%;
      right: 0%;
      transform: translate(0%, -50%);
    }

https://jsfiddle.net/lalji1051/L7dnvqbm/1/

关于html - 我想将搜索栏对齐到最右边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56866438/

相关文章:

python - 从给定网页收集*所有*链接,然后按短语搜索它们

html - 我可以用 CSS(没有 JS)重新启动 gif 吗?

html - IE 和 FF 之间的 CSS 差异

c++ - 放置新的错误警告?

delphi - Delphi 7 中的 DateTimePicker 对齐

javascript - 在 PC 和移动浏览器中运行的隐藏和显示切换

javascript - 如何在Jquery中迭代Table来更改内容

javascript - 隐藏/显示多个 div

html - 如何消除旋转元素之间的间距?

javascript - 在 HTML 中使用 Canvas 时不显示文本