更改超棒的圆形图标的背景颜色

时间:2018-09-07 07:56:13

标签: html css html5 css3 font-awesome

我正在使用2个字体超赞的图标,前面是+,后面是圆圈。

这里是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>

如何解决此问题?

3 个答案:

答案 0 :(得分:1)

在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>

答案 1 :(得分:0)

尝试使用此HTML和CSS。我删除了整个黑色圆圈,并用CSS的clip-path属性替换了它作为加号的背景(它在大中型屏幕上效果很好,但遗憾的是,在小到大屏幕上效果不佳)小屏幕,所以我必须为.wrapper跨度设置一个min-width属性:

.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;
}
.fa-plus{
  background:black;
  -webkit-clip-path: circle(38% at 50% 50%);
  clip-path: circle(38% at 50% 50%);
}
<!-- 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>

答案 2 :(得分:0)

将.wrapper span CSS属性替换为以下内容:

.wrapper span {

    position: absolute;
    bottom: 0;
    right: 15%;
    width: 20px;
    height: 20px;
    z-index: 2;
    padding: 0;
    line-height: 20px;
}