[Solved] How to make collage of absolutely positioned images responsive

NamelessDude21 Asks: How to make collage of absolutely positioned images responsive
I have a collage dogAPI app that randomly positions imgs on the screen. I need these images to stay within the viewport otherwise you will be scrolling for a very long time. I have tried editing the moveImg function to use %’s instead of px’s but this actually makes it worse.

Code:
//show image in a random location
let moveImg = (dogImgs) => {
    let w = window.innerWidth;
    let h = window.innerHeight;
    dogImgs.style.top = getRandomNum(w) + "%";
    dogImgs.style.left = getRandomNum(h) + "%";
};

https://codepen.io/drxl/pen/VwbQZyK

Code:
     <!--Title and menu-->
<div class="main-container">
    <div class="header">
        <h1>Dog Collage!</h1>
        <p>Select a dog and create your collage!</p>
        <p>Double-tap to remove an image.</p>
        <div id="breeds"></div>
    </div>
    <div id="img-container">
        <div class="slideshow" id="imgs">
        </div>   
    </div>
         
</div>

.main-container  {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.slideshow {
    text-align: center;
}

img {
    max-width: 40%;
    margin-top: 25rem;
    position: absolute;
}

//Get a random number
let getRandomNum = (num) => {
    return Math.floor(Math.random() * Math.floor(num));
}

//show image in a random location
let moveImg = (dogImgs) => {
    let w = window.innerWidth;
    let h = window.innerHeight;
    dogImgs.style.top = getRandomNum(w) + "px";
    dogImgs.style.left = getRandomNum(h) + "px";
};

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.