I’ve finished Basic HTML & CSS section and there was this penguin at the end. Since there was no explanation on how to create one and I wanted to understand better how things work, I made this thing to play around with positioning:
<style>
:root {
--leaf-color: #C0C0C0;
--hover-color: #ffbbbb;
}
.container {
position: relative;
margin: auto;
display: block;
width: 500px;
height: 500px;
}
.top-left {
top: 50%;
left: 19%;
background-color: var(--leaf-color);
transition: background-color .5s;
width: 30%;
height: 30%;
border-radius: 120% 10% 10% 10%;
}
.top-left:hover {
background-color: var(--hover-color);
}
.top-right {
top: 50%;
left: 50%;
background-color: var(--leaf-color);
transition: background-color .5s;
width: 30%;
height: 30%;
border-radius: 10% 120% 10% 10%;
}
.top-right:hover {
background-color: var(--hover-color);
}
.bottom-left {
top: 81%;
left: 19%;
background-color: var(--leaf-color);
transition: background-color .5s;
width: 30%;
height: 30%;
border-radius: 10% 10% 10% 120%;
}
.bottom-left:hover {
background-color: var(--hover-color);
}
.bottom-right {
top: 81%;
left: 50%;
background-color: var(--leaf-color);
transition: background-color .5s;
width: 30%;
height: 30%;
border-radius: 10% 10% 120% 10%;
}
.bottom-right:hover {
background-color: var(--hover-color);
}
.container * {
position: absolute;
}
</style>
<div class="container">
<div class="top-left"></div>
<div class="top-right"></div>
<div class="bottom-left"></div>
<div class="bottom-right"></div>
</div>
What I don’t understand is how can I center the whole thing (vertically and horizontally)? I can move around single elements and play around with numbers to make it look like it’s centered, but once I open it on a bigger monitor it all seems to be off.
Thanks in advance.