如何使图标紧贴其文字?

时间:2018-09-04 12:49:43

标签: css sass bootstrap-4 font-awesome

我正在尝试构建一个响应迅速的上标头as you see in this screenshot

当您看到消息图标在文本显示时仍然挂起的问题 只要宽度在757和575之间。

总体来说,我在CSS和Bootstrap 4中还是新手。

先谢谢您!

.upper-bar {
  font-family: Times;
  background-color: #007872;
  color: #fff;
}

.upper-bar a {
  color: #fff;
}

.upper-bar-left,
.upper-bar-right {
  margin: 15px 0;
  text-align: center;
  padding-left: 0;
}

@media (max-width: 575.98px) {
  .upper-bar-left:first-child,
  .upper-bar-right:first-child {
    margin-bottom: 0;
  }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<div class="upper-bar">
  <div class="container">
    <div class="row">

      <div class="col-sm upper-bar-left text-sm-left">
        <i class="fa fa-phone"></i> 00000009890
        <i class="far fa-envelope"></i><a href="mailto:lorem_ipsuml@xxxxx.xx"> lorem_ipsuml@xxxxx.xx</a>
      </div>

      <div class="col-sm upper-bar-right text-sm-right">
        <i class="fas fa-map-marker"></i> LOrem Ipsum 0, 00098 Loremipsum
      </div>

    </div>
  </div>
</div>

Codepen: https://codepen.io/anon/pen/bxREoK?editors=1100

3 个答案:

答案 0 :(得分:2)

将信封图标和电子邮件锚定保留在具有text-nowrap类的范围内

<span class="text-nowrap">
    <i class="far fa-envelope"></i>
    <a href="mailto:lorem_ipsuml@xxxxx.xx"> lorem_ipsuml@xxxxx.xx</a>
</span>

有关文本nowrap的信息,请参见this

.upper-bar {
  font-family: Times;
  background-color: #007872;
  color: #fff;
}

.upper-bar a {
  color: #fff;
}

.upper-bar-left,
.upper-bar-right {
  margin: 15px 0;
  text-align: center;
  padding-left: 0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">


<script src="https://use.fontawesome.com/2972279885.js"></script>

<div class="upper-bar">
  <div class="container">
    <div class="row">

      <div class="col-sm upper-bar-left text-sm-left">
        <i class="fa fa-phone"></i> 0542 1421455
        <span class="text-nowrap">
          <i class="fa fa-envelope"></i>
          <a href="mailto:lorem_ipsuml@xxxxx.xx"> lorem_ipsuml@xxxxx.xx</a>
         </span>
      </div>

      <div class="col-sm upper-bar-right text-sm-right">
        <i class="fas fa-map-marker"></i> LOrem Ipsum 0, 00098 Loremipsum
      </div>

    </div>
  </div>
</div>

答案 1 :(得分:0)

我建议您可以这样做:

html

<div class="icon-text">
<i class="fab fa-facebook-f">
<p> Your text</p>
</div>

css

.icon-text {
display: inline-block;
margin-right: 20px;
}

答案 2 :(得分:-2)

请尝试这种方式。

CSS代码:

.left-style{
float:left;
}

HTML代码:

<div class="col-sm upper-bar-left text-sm-left">
        <span class="left-style"><i class="fa fa-phone"></i> 00000009890</span>
        <span class="left-style"><i class="far fa-envelope"></i>
<a href="mailto:lorem_ipsuml@xxxxx.xx"> lorem_ipsuml@xxxxx.xx</a></span>
</div>