Can someone help me figure out how to position an image so that it appears exactly at the halfway point of the screen?
I've researched different ways to position images within a div, but I'm struggling with positioning it on the entire screen.
I've experimented with using position: absolute;
, background-position
, and other CSS styles without success.
Percentages don't seem to work as expected because the image moves when the screen is resized, not staying fixed on its vertical axis.
.background {
position: absolute;
top: 10px;
left: 50%;
width: 50%;
height: 250px;
background-image: url('https://www.google.com/logos/doodles/2020/december-holidays-days-2-30-6753651837108830.3-law.gif');
background-position: 0 0;
background-repeat: no-repeat;
background-size: cover;
}
<html>
<body>
<div class="background">
</div>
</body>
</html>