简体   繁体   English

如何改变bootstrap glyphicon的颜色?

[英]How to change color of bootstrap glyphicon .?

How do I change the color of my star glyphicon? 如何更改星形雕ly的颜色? My code is 我的代码是

<span  class="glyphicon glyphicon-star-empty " onclick = "addToFav()">      </span> 

I am calling a javascript function on the click of glyphicon. 我在点击glyphicon时调用了javascript函数。 I also want to change the color of the glyphicon as shown in the image below. 我还想更改glyphicon的颜色,如下图所示。 I tried changing the background color of the gyphicon but it doesn't give me the desired output. 我尝试更改gyphicon的背景颜色,但它没有提供所需的输出。 **Update"' On changing the style.color of the glyphicon, it just changes the color of the glyphicon but doesn't fill the glypicon with the desired color. The first image is the original glyphicon. The second image is the desired result. The third image is the glyphicon on changing the background color of the glyphicon. The fourth image shows what happens to glyphicon on changing style.color of glyphicon to red. **“更新”'在更改字形图标的style.color时,它只是更改了字形图标的颜色,但没有用所需的颜色填充字形图标。第一个图像是原始字形图标。第二个图像是所需的结果第三张图是改变字形背景色的字形图,第四张图显示了将字形颜色从红色改变为红色的字形图。 我的Glyphicon 单击后所需的Glyphicon 单击时更改背景颜色的结果错误 关于改变字形的颜色

Try with this. 试试这个。

 <span  class="glyphicon glyphicon-star-empty " onclick = "addToFav(this)"> </span> 
<script>
    function addToFav(ths){
        ths.style.color = "#ffea00";
    }
</script>
 <span class="glyphicon glyphicon-print" style="color:red;background-color:blue;padding:10px"></span>

您可以更改颜色,背景色,填充等的更改方式

If I understand the question correctly, you want to change the star from a black outline to a filled yellow star? 如果我对问题的理解正确,您想将星形从黑色轮廓更改为实心黄色星形吗? If so, then you'll need to change not just the style to set the color , but you'll also need to replace the class glyphicon-star-empty with the class glyphicon-star . 如果是这样,那么你就需要改变不只是风格来设置color ,但你也需要更换类glyphicon-star-empty与类glyphicon-star

The following code worked out the best for me. 以下代码最适合我。 In my class list for glyphicon, I added both, the class for filled star and the class for the empty star. 在我的glyphicon类别列表中,我同时添加了实心星星类和空星星类。 The empty star class is written after the star class and thus it overrides the filled star class and hence, initially I get the empty start on the screen. 空的星形类是在星形类之后编写的,因此它会覆盖填充的星形类,因此,最初,我在屏幕上获得了空的开始。 The code is as follows 代码如下

<span id="star-glyp"class="glyphicon glyphicon-star glyphicon-star-empty" onclick = "addToFav()">

On clicking this glyphicon, I call addToFav() function. 单击此字形图标后,我将调用addToFav()函数。 In this function, I am doing two things to produce the desired output. 在此功能中,我正在做两件事以产生所需的输出。 First, I am changing the color of the glyphicon to yellow. 首先,我将字形图标的颜色更改为黄色。 Second, I am removing the glyphicon-star-empty class from my class list. 其次,我要从班级列表中删除glyphicon-star-empty班级。 The code is as follows: 代码如下:

 function addToFav(){

                ths = document.getElementById("star-glyp");
                ths.style.color="YELLOW";
                ths.classList.remove('glyphicon-star-empty');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM