【问题标题】:Make Font Awesome icons in a circle border with right 1:1 ratio以 1:1 的比例在圆形边框中制作 Font Awesome 图标
【发布时间】:2017-05-22 19:43:59
【问题描述】:

在某些情况下,如果图标的比例不是 1:1,那么边框就不再是圆形了。

这是一个例子:

我目前正在使用:

HTML:

.socials
      a(href='#') <i class="fa fa-facebook"></i>
      a(href='#') <i class="fa fa-twitter"></i>
      a(href='#') <i class="fa fa-google"></i>

SASS:

      border-radius: 50%
      border: solid white
      padding: 10px

无论如何我可以使用 CSS 来解决问题吗?

【问题讨论】:

标签: html css border font-awesome


【解决方案1】:

您需要设置宽度、高度、行高和文本对齐以使图标居中。 图标也需要垂直对齐重置为中间。

避免以像素为单位填充,但在 em 或 rem 中使用宽度/高度/行高。然后,您可以更改字体大小并保持比例而不更新其他值。

a /* or selector a .fa */
  {  
  font-size:3em;
  border-radius: 50%;
  border: solid white;
  color: white;
  line-height: 2em;
  width: 2em;
  height: 2em;
  text-align: center;
  display: inline-block;
    transition:0.5s;
}
/* demo purpose */
a:hover {font-size:2em}
.fa {
/* optionnal vertical-align: middle;*/
}
body {
  background: #333
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<a href="#"><i class="fa fa-facebook"></i></a>
<a href="#"><i class="fa fa-twitter"></i></a>
<a href="#"> <i class="fa fa-google"></i>
</a>

【讨论】:

    【解决方案2】:

    设置固定的widthheight,并使用text-align:center

    i {
      border-radius: 50%;
      border: solid black;
      padding: 10px;
      width:16px;
      height: 16px;
      text-align:center
    }
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <i class="fa fa-facebook"></i>
    <i class="fa fa-twitter"></i>
    <i class="fa fa-google"></i>

    【讨论】:

      【解决方案3】:

      border-radius 中的百分比计算为宽度和高度不同的百分比。尝试 50px 进行考试。

      div {
        margin: .3em;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 2em;
        color: white;
      }
      .pc {
        width: 200px;
        height: 80px;
        background-color: blue;
        border-radius: 50%;
      }
      .px {
        width: 200px;
        height: 80px;
        background-color: blue;
        border-radius: 50px;
      }
      <div class="pc">%</div>
      <div class="px">px</div>

      【讨论】:

      • 非常感谢@AndreyFedorov。感谢您的回答和宝贵的时间。谢谢
      【解决方案4】:

      要实现它同时保持图标的纵横比,您需要以 1:1 的比例(与高度相同)为图标分配一个容器。

      i.fa-facebook {
        padding: 10px;
        color: white;
      }
      
      .border {
        border-radius: 50%;
        border: solid white;
      }
      
      a.icon_container {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: solid white;
        text-align: center;
        float: left;
      }
      
      body {
        background: black;
      }
      <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
      <i class="fa fa-facebook border"></i>
      <a href="#" class="icon_container border"><i class="fa fa-facebook"></i></a>

      【讨论】:

        猜你喜欢
        • 2014-10-01
        • 2023-03-16
        • 2021-05-10
        • 1970-01-01
        • 1970-01-01
        • 2020-11-17
        • 2020-07-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多