用css替换当前的html图像

use*_*423 2 html css css3

我在尝试用CSS替换此图像时遇到问题,我无法访问html.

http://jsfiddle.net/ES4mH/

<img 
  width="64" 
  height="64" 
  border="0" 
  style="width: 64px; height: 64px;" 
  src="http://www.nitrografixx.com/2013/lock-icon.gif">
</img>
Run Code Online (Sandbox Code Playgroud)

我试过这个,虽然它将图像作为背景添加到当前图像,但它不会取代它.

img[src='http://www.nitrografixx.com/2013/lock-icon.gif'] {
  background: url(http://www.nitrografixx.com/2013/lock_bg.jpg) center !important;  
}
Run Code Online (Sandbox Code Playgroud)

PSR*_*PSR 8

试试这个

<style>
.className{
    content:url("http://www.nitrografixx.com/2013/lock_bg.jpg");
}
</style>
<img class="className"/>
Run Code Online (Sandbox Code Playgroud)

  • 由于OP具有对HTML无法访问,你需要改变`.className`到`IMG [SRC = 'HTTP://www.nitrografixx.com/2013/lock-icon.gif']`? (4认同)