snapp
snapp

Reputation:

replace image through css

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

Upvotes: 7

Views: 14511

Answers (4)

Musawar ahmed
Musawar ahmed

Reputation: 82

replace the img src

.image-replacement {
  display: block;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  background: url(https://www.whatsappimages.in/wp-content/uploads/2021/07/Top-HD-sad-quotes-for-whatsapp-status-in-hindi-Pics-Images-Download-Free.gif)
    no-repeat;
  width: 180px;
  height: 236px;
  padding-left: 180px;
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h2>Image replaced with Image</h2>
<img class="image-replacement" src="https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW58ZW58MHx8MHx8&w=1000&q=80" />
</body>
</html>

Upvotes: -1

costumingdiary
costumingdiary

Reputation: 317

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.

Upvotes: 1

Andras
Andras

Reputation: 51

You can try this:

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

Works in Chrome, not in Firefox...

Upvotes: 5

Mikko Tapionlinna
Mikko Tapionlinna

Reputation: 1458

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;
}

Upvotes: 7

Related Questions