如何在同一行中显示按钮和字体图标

时间:2019-01-29 13:13:53

标签: html5 css3 bootstrap-4 font-awesome

.add-cart-button
{
    width:205px;
    height:56px;
    border-radius: 28px;
    background-color: #EC7F4A;
    color: #ffff;
    font-family: Roboto;
}
.add-cart-button-icon
{
    color: #232323;
    float: right;
    font-size: 40px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <button  class="add-cart-button">
    <span>Add to Cart</span><i class="fa fa-plus-circle fa-6  add-cart-button-icon" aria-hidden="true"></i>
   </button>

我在按钮中使用Bootstrap4怀疑我需要同时显示按钮和fontawosome图标。任何人都可以告诉我去做。

Expected image

我现在得到的实际输出

Image of Actual output i got now

1 个答案:

答案 0 :(得分:0)

您只需在按钮内添加<i>标签即可。

编辑:我已经将您的代码添加到了相同的代码段中。只需将line-height: 40px;添加到add-cart-button类中即可提供对齐修复。

.round-btn {
  border-radius: 19px !important;
}

.add-cart-button {
  width: 205px;
  height: 56px;
  border-radius: 28px;
  background-color: #EC7F4A;
  color: #ffff;
  font-family: Roboto;
  line-height: 40px;
}

.add-cart-button-icon {
  color: #232323;
  float: right;
  font-size: 40px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">


</head>

<body>

  <div class="container">
    <button type="button" class="btn btn-warning round-btn">Warning<i class="pl-2 fa fa-plus-circle"></i></button>

    <button class="add-cart-button">
    <span>Add to Cart</span><i class="fa fa-plus-circle fa-6  add-cart-button-icon" aria-hidden="true"></i>
   </button>
  </div>


</body>

</html>