replace image through css

走远了吗. 提交于 2020-01-02 04:20:40

问题


I'm writing code in Stylish, a firefox plugin, to change the image that is showing up.

The image property doesn't have a div tag, so I have to use this:

img[src*="s_dschjungelplanet"]{
##########
}

So this will replace "s_dschjungelplanet" anywhere in the page, in a img src.

So my main problem is that I'm not sure HOW to tell it to replace the src="xxx".

Ta for replies


回答1:


There is no easy way. I think you'd be better of with greasemonkey scripts, as with a simple such script you can change the url.

As far as I know, you can not change the url with css only. This was the closest I was able to come with css only:

img[src*="s_dschjungelplanet"]{
    width:0;
    height:70px;
    padding-right:250px;
    background:transparent url(http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png) top left no-repeat;
}



回答2:


You can try this:

img[src*="s_dschjungelplanet"]{ content: url("myfavorite.png"); }

Works in Chrome, not in Firefox...




回答3:


img[src*="http://url-of-image-to-be-replaced.jpg"]{
    background-image: url("https://url-of-image-you-want-to-display.jpg");
    width:38px;
    display:inline-block;
    padding:38px 0 0 0;
    height: 0px}

Change the width and padding to your specs. It's worked for me.



来源:https://stackoverflow.com/questions/694486/replace-image-through-css

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