html改变src颜色,css – img src SVG更改填充颜色

您需要使SVG成为内联SVG。您可以使用此脚本,通过向图像添加类svg:

/*

* Replace all SVG images with inline SVG

*/

jQuery('img.svg').each(function(){

var $img = jQuery(this);

var imgID = $img.attr('id');

var imgClass = $img.attr('class');

var imgURL = $img.attr('src');

jQuery.get(imgURL,function(data) {

// Get the SVG tag,ignore the rest

var $svg = jQuery(data).find('svg');

// Add replaced image's ID to the new SVG

if(typeof imgID !== 'undefined') {

$svg = $svg.attr('id',imgID);

}

// Add replaced image's classes to the new SVG

if(typeof imgClass !== 'undefined') {

$svg = $svg.attr('class',imgClass+' replaced-svg');

}

// Remove any invalid XML tags as per http://validator.w3.org

$svg = $svg.removeAttr('xmlns:a');

// Check if the viewport is set,if the viewport is not set the SVG wont't scale.

if(!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {

$svg.attr('viewBox','0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))

}

// Replace image with new SVG

$img.replaceWith($svg);

},'xml');

});

然后,现在如果你做:

.logo-img path {

fill: #000;

}

或者可能:

.logo-img path {

background-color: #000;

}

这工作!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值