您可以使用CSS来实现这一效果。以下是一种可能的解决方案:

HTML代码:

<div class="search-container">
  <input type="text" class="search-box" placeholder="搜索...">
  <button class="search-button">搜索</button>
</div>

CSS代码:

.search-container {
  display: flex;
  align-items: center;
}

.search-box {
  flex: 1;
}

.search-button {
  margin-left: 10px;
}

解释:

  • 通过将搜索框和搜索按钮放置在一个容器内,我们可以使用flex布局来控制它们的位置。
  • display: flex属性将容器设置为一个弹性容器。
  • align-items: center属性使容器内的元素在垂直方向上居中对齐。
  • flex: 1属性使搜索框占据剩余的可用空间。
  • margin-left: 10px属性将搜索按钮的左外边距设置为10像素,从而将其与搜索框分开。

通过这些CSS样式,搜索框将居左显示,并且搜索按钮将在搜索框的右边显示

如何让这个搜索框居左并让搜索按钮在它右边?

原文地址: https://www.cveoy.top/t/topic/iRND 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录