I am currently working on a CSS scene creation project and utilizing position: relative
and position:absolute
.
However, I am facing an issue with trying to position my child div at the center of its parent div using various CSS properties.
This is what I have implemented:
.game {
background-color: #5386e4;
overflow: hidden;
position: relative;}
.fish {
height: 320px;
width: 300px;
position: absolute; // Setting position as absolute
transform-origin: center; // Attempting to set the origin of the div to be centered.
top: 50%; // Trying to vertically center the child div within the parent div.
left: 50%; // Similarly, attempting horizontal centering.
z-index: 10000;
background-color: #10121b;}
However, here is the result produced: https://i.sstatic.net/cYvR4.png
Please note that my div .game
itself is a child of another div. Feel free to ask if you require further details regarding my HTML or CSS structure.