How to round font-awesome icons?

隐身守侯 提交于 2021-02-09 11:32:26

问题


I am trying to round font-awesome icon. Please refer - http://jsfiddle.net/JfGVE/1704/

The problem is, not matter what, the rounded icon is more oval. Not able to make it a perfectly rounded. Below is the css code i have -

i {
display: inline-block;
background: gray;
color: white;
border-radius: 50%;
padding: 5px;
}

回答1:


Try to adjust height/width and reset line-height:

i {
  display: inline-block;
  background: gray;
  color: white;
  border-radius: 50%;
  padding: 0.3em; /* adjust padding */
  line-height: initial !important; /* reset line-height */
  height: 1em;
  width: 1em;
  text-align:center;
}
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
<i class="fa fa-close"></i>
<br>
<i class="fa fa-camera-retro fa-lg"></i> fa-lg
<i class="fa fa-camera-retro fa-2x"></i> fa-2x
<i class="fa fa-close fa-3x"></i> fa-3x
<i class="fa fa-info fa-4x"></i> fa-4x
<i class="fa fa-camera-retro fa-5x"></i> fa-5x

[Edit] the icon size is not equal height/width. So I changed the answer and added height: 1em; width: 1em; text-align: center;




回答2:


It's preferable to avoid setting fixed width and height in pixels. Here's a sollution using an extra div with after pseudo element to draw the circle, see DEMO

HTML:

<div class="container">
  <i class="fa fa-close"></i>
</div>

CSS:

.container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: #555;
  min-width: 2em;
  border-radius: 50%;
  vertical-align: middle;
}

.container:after {
  content:'';
  float: left;
  width: auto;
  padding-bottom: 100%;
}



回答3:


Just use this:

<i class="fa fa-times-circle"></i>

or if you want you can try this too:

i.custom {
  display: inline-block;
  background: gray;
  color: white;
  border-radius: 50%;
}
i.custom:before,
i.custom:after {
  display: inline-block;
  vertical-align: middle;
  height: 40px;
  width: 40px;
  line-height: 40px;
  text-align: center;
}
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
<i class="custom fa fa-close"></i>
<i class="fa fa-times-circle"></i>


来源:https://stackoverflow.com/questions/40883157/how-to-round-font-awesome-icons

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