html - 更改 font-awesome 圆形图标的背景颜色

标签 html css font-awesome

我使用了 2 个来自 font-awesome 的图标,一个 + 在前面,一个圆圈在后面。

这是一个fiddle

我正在尝试更改圆圈的背景颜色,但它不起作用。

代码如下:

.fa-plus{
    background-color: red;
    border-radius: 50%;
}

.wrapper{
  position: relative;
  width: 20%;
  height: 20%;
  margin: auto;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #000;
}

.image{
  max-width: 100%;
  border-radius: 50%
}

.wrapper span{
  position: absolute;
  bottom: 0;
  right: 15%;
  width: 15%;
  height: 15%;
  z-index: 2;
}

#input{
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: -1;
  cursor: pointer;
  opacity: 0;
}
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="wrapper">
  <input type="file" id="input" name="image" accept="image/*">
  <img class="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTRT2XK4W0i7icS84Yq5VHpwZ9anmDXoOFQZX0anUhWxcpL5du_">
  <span class="fa-stack" aria-hidden="true">
    <i class="fa fa-circle fa-stack-2x"></i>
    <i class="fa fa-plus fa-stack-1x fa-inverse"></i>
  </span>
</div>

我正在使用圆圈为 + 图标提供圆形背景颜色,我尝试仅添加 + 图标并为其提供 padding,但也没有用:

.fa-plus{
    background-color: red;
    border-radius: 50%;
}

.wrapper{
  position: relative;
  width: 20%;
  height: 20%;
  margin: auto;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #000;
}

.image{
  max-width: 100%;
  border-radius: 50%
}

.wrapper span{
  position: absolute;
  bottom: 0;
  right: 15%;
  width: 15%;
  height: 15%;
  z-index: 2;
  padding: 10%;
}

#input{
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: -1;
  cursor: pointer;
  opacity: 0;
}
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="wrapper">
  <input type="file" id="input" name="image" accept="image/*">
  <img class="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTRT2XK4W0i7icS84Yq5VHpwZ9anmDXoOFQZX0anUhWxcpL5du_">
  <span class="fa-stack" aria-hidden="true">
    <i class="fa fa-plus fa-stack-1x fa-inverse"></i>
  </span>
</div>

如何解决这个问题?

最佳答案

在 CSS 中添加此属性。

i.fa.fa-circle.fa-stack-2x{
color:green;
}

如果你想把加号背景从红色变成绿色(我没有包含在代码片段中)

i.fa.fa-plus.fa-stack-1x.fa-inverse {
background: green;
}

.fa-plus{
    background-color: red;
    border-radius: 50%;
}
i.fa.fa-circle.fa-stack-2x{
color:green;
}
.wrapper{
  position: relative;
  width: 20%;
  height: 20%;
  margin: auto;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #000;
}

.image{
  max-width: 100%;
  border-radius: 50%
}

.wrapper span{
  position: absolute;
  bottom: 0;
  right: 15%;
  width: 15%;
  height: 15%;
  z-index: 2;
}

#input{
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: -1;
  cursor: pointer;
  opacity: 0;
}
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="wrapper">
  <input type="file" id="input" name="image" accept="image/*">
  <img class="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTRT2XK4W0i7icS84Yq5VHpwZ9anmDXoOFQZX0anUhWxcpL5du_">
  <span class="fa-stack" aria-hidden="true">
    <i class="fa fa-circle fa-stack-2x"></i>
    <i class="fa fa-plus fa-stack-1x fa-inverse"></i>
  </span>
</div>

关于html - 更改 font-awesome 圆形图标的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52217913/

相关文章:

javascript - 使用 ng-repeat 填充 "x - available elements"的剩余元素

css - 防止列调整内容大小

css - Wordpress.com - 保存自定义 CSS 后所有宽度都被删除

css - 在同一行上对齐文本和图像,同时保持相对于容器大小的文本缩进

reactjs - 如何在模块化 CSS React 中更改 fontawesome 图标的颜色

html - 倾斜动画让img跑满整个页面

html - CSS 库(例如 :Bootstrap) that supports IE6?

javascript - 如何在考勤管理系统的数据库中保存当前、缺勤的学生名单?

html - 特定的 css 类将在 IE8 浏览器中执行并且 border-radius 不起作用

css - 如何水平居中 Font Awesome 图标?