css 对齐图标与文本框引导

mbskvtky  于 2023-02-10  发布在  其他
关注(0)|答案(2)|浏览(140)

我希望图标与文本框对齐并在容器上居中
我试过这个,但图标停留在文本框上方

<div class="container d-flex justify-content-center" id="baseContainer">
    <div class="row">
        <input type="text" class="input-form col-sm-3 offset-sm-0" id="searchForm" placeholder="Busque um filme ou série">
        <i class="fa-solid fa-magnifying-glass col-sm" onclick="foo()"></i>
    </div>
</div>

如果我删除行和容器div,保持我想要的方式,但不居中

q3qa4bjr

q3qa4bjr1#

将类align-items-center添加到

<div class="container d-flex justify-content-center" id="baseContainer">
    <div class="row align-items-center">
        <input type="text" class="input-form col-sm-3 offset-sm-0" id="searchForm" placeholder="Busque um filme ou série">
        <i class="fa-solid fa-magnifying-glass col-sm" onclick="foo()"></i>
    </div>
</div>
mpgws1up

mpgws1up2#

您可以使用Flexbox垂直对齐搜索图标:

<div class="container d-flex justify-content-center" id="baseContainer">
  <div class="row">
    <input
      type="text"
      class="input-form col-sm-3 offset-sm-0"
      id="searchForm"
      placeholder="Busque um filme ou série"
    />
    <i
      class="fa-solid fa-magnifying-glass col-sm d-flex align-items-center"
      onclick="foo()"
    ></i>
  </div>
</div>

相关问题