0

我在导航栏上的搜索按钮有一个引导图标和未垂直对齐的文本

小提琴链接:小提琴

用于搜索的html:

            <form class="d-flex search-form">
                <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
                    <button class="btn btn-dark" type="submit">
                        <div class="nav-search">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search nav-svg" viewBox="0 0 16 16">
                        <path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/>
                    </svg>
                    Search
                </input>
                </button>
            </form>

我尝试过的搜索中的css:

.nav-search {
   display: inline-block;
}

.search-form {
    text-align: center;
    width: 100%;
}
4

2 回答 2

0

更改 viewBox 属性值以定义用户空间中的位置和尺寸。这是相同的文档:viewBox

于 2021-08-18T09:13:32.750 回答
0

您可以使用display:flexwithalign-items将图标与文本垂直对齐。

.nav-search {
   display: flex;
  align-items: center;

}
  <form class="d-flex search-form">
    <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-dark" type="submit">
      <div class="nav-search">
        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search nav-svg" viewBox="0 0 16 16">
          <path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" />
        </svg>
        Search
      </div>
    </button>

  </form>

于 2021-08-18T09:16:45.863 回答