Glyphicon not working in bootstrap version 4.1 and later

本小妞迷上赌 提交于 2020-02-23 09:58:46

问题


I tried to show a search icon in form but the only button is shown without the glyphs.

<form class="form-inline my-2 my-lg-0">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</form>  

RESULT

I use bootstrap version 4.1. I got the glyphicon code getbootstrap.com and form getbootstrap.com

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />

<form class="form-inline my-2 my-lg-0">
  <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
  <button class="btn btn-outline-success my-2 my-sm-0" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</form>

回答1:


Glyphicons are dropped from Bootstrap V4 and later.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<form class="form-inline my-2 my-lg-0">
  <div class="input-group">
    <input class="form-control" type="search" placeholder="Search">
    <div class="input-group-append">
      <div class="input-group-text"><i class="fa fa-search"></i></div>
    </div>
  </div>
</form>

Here, Font Awesome is used. Refer this answer for more alternatives to Glyphicons and Font Awesome




回答2:


Bootstrap 4 dropped the Glyphicons icon font.

https://getbootstrap.com/docs/4.0/migration/#components



来源:https://stackoverflow.com/questions/49905458/glyphicon-not-working-in-bootstrap-version-4-1-and-later

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!