P粉7224099962023-08-28 11:19:21
1- Put your image into a container.
2- Give the container a fixed width
and height
, and a fixed min-height
and min-width
, It can be set according to your needs or the resolution of the picture.
That's it.
Don't worry about the js code, I just want to show the image after 3 seconds to help you understand what I mean.
var image = document.querySelector(".image"); image.style.display = "none"; setTimeout(() => { image.style.display = "block"; }, 3000);
.image-container { width: 350px; min-width: 350px; height: 250px; min-height: 250px; border: 1px solid red; } .image { width: 350px; min-width: 350px; height: 250px; min-height: 250px; }
<h2 class="before">This is text before</h2> <div class="image-container"> <img class="image" src="https://images2.minutemediacdn.com/image/fetch/w_850,h_560,c_fill,g_auto,f_auto/https%3A%2F%2Fwinteriscoming.net%2Ffiles%2F2021%2F11%2FCaraxes-850x560.jpeg" alt=""> </div> <h2 class="after">This is text after</h2>