1

i have a class boxright with backgrround image of cave

i have a button which on onclick it points to function ontop() which reset the backgroundimage of boxright to an image cheetah

i want the cheetah to appear on top the cave, ie on buttonclick i want the cheeteh to appear inside the cave

How to achieve this?

function ontop()
{
var d=document.getElementById('a').style.backgroundImage="url(https://i.ibb.co/0DvMRj4/wcheetah.png)";
console.log(d);
}
.boxright {
  position: absolute;
  top: 48.3vh;
  left: 50.98vw;
  
  width: 14.0vw;
  height: 40.0vh;
  
  cursor:pointer;
  border:2px solid black;
  background-image:url(https://i.ibb.co/cYnc1Ky/kisspng-cave-euclidean-vector-illustration-vector-cave-5a7a360b205458-5617697615179586671324.png);
  background-repeat:no-repeat;
  background-size:cover;
  
  }
<div class="boxright" id="a"></div>
<button onclick="ontop();">place another image indide cave</button>

6
  • 1
    Expected output? Commented Dec 5, 2018 at 5:56
  • 1
    position the cheeteh inside or top? Commented Dec 5, 2018 at 5:56
  • @prashant-pimpale on buttonclick i want the cheetah to apper inside the cave Commented Dec 5, 2018 at 5:58
  • @%d7%9c%d7%91%d7%a0%d7%99-%d7%9e%d7%9c%d7%9b%d7%94 wanto position cheetah so that it appear inside the cave Commented Dec 5, 2018 at 6:00
  • 1
    Like, push new image inside current div? Commented Dec 5, 2018 at 6:04

1 Answer 1

2

on click add class to div that in css add pseudo element with the image

function ontop()
{
   document.getElementById('a').classList.add('cheeteh');
}
.boxright {
  position: absolute;
  top: 48.3vh;
  left: 50.98vw;
  width: 14.0vw;
  height: 40.0vh;
  cursor:pointer;
  border:2px solid black;
  background-image:url(https://i.ibb.co/cYnc1Ky/kisspng-cave-euclidean-vector-illustration-vector-cave-5a7a360b205458-5617697615179586671324.png);
  background-repeat:no-repeat;
  background-size:cover;
  
  }
  .cheeteh:after{
    content: "";
    position: absolute;
    top: 50%;
    background-image: url(https://i.ibb.co/0DvMRj4/wcheetah.png);
    z-index: 4;
    width: 50%;
    height: 50%;
    background-size: 100% 100%;
  }
  
<div class="boxright" id="a"></div>
<button onclick="ontop();">place another image on top</button>

Sign up to request clarification or add additional context in comments.

2 Comments

@%d7%9c%d7%91%d7%a0%d7%99-%d7%9e%d7%9c%d7%9b%d7%94 psedo element works perfect... great information brother
happy to help and I am sister ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.