Results preview
Press the right "click the Preview" button to preview the current page, click on the link to full-screen preview.
https://codepen.io/comehope/pen/OEBJRN
Interactive video
This video is interactive, you can pause the code video, editing video.
Please use chrome, safari, edge open view.
https://scrimba.com/p/pEgDAM/c6bkqT2
Source code download
Daily front-end combat series full source code can be downloaded from github:
https://github.com/comehope/front-end-daily-challenges
Code Reading
Defined dom, container 5 contains elements representing the body, button, legs, handles and bread.
<div class="toaster">
<div class="body"></div>
<div class="button"></div>
<div class="legs"></div>
<div class="handle"></div>
<div class="toast"></div>
</div>
Centered:
body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(to right bottom, moccasin, teal);
}
Is defined container sizes:
.toaster {
width: 30em;
height: 30em;
background-color: snow;
font-size: 10px;
border-radius: 50%;
}
Draw the body:
.toaster {
position: relative;
}
.body {
width: 16em;
height: 14em;
background-color: seagreen;
position: absolute;
top: 10em;
left: 6em;
border-radius: 2.5em;
border-right: 1.5em solid darkgreen;
}
Draw button:
.button {
width: 2.5em;
height: 2.5em;
background-color: tomato;
position: absolute;
top: 13em;
left: 16em;
border-radius: 50%;
}
Draw legs:
.legs::before,
.legs::after {
content: '';
position: absolute;
width: 1.5em;
height: 2em;
background: tomato;
top: 24em;
}
.legs::before {
left: 9em;
}
.legs::after {
right: 10em;
}
Draw Handle:
.handle {
width: 4.2em;
height: 1.8em;
background-color: tomato;
position: absolute;
top: 12em;
right: 2.4em;
border-radius: 0 0.6em 0.6em 0;
}
Draw bread:
.toaster {
z-index: 1;
}
.toast {
width: 9em;
height: 6em;
background-color: gold;
position: absolute;
top: 4em;
left: 10em;
border-radius: 2em 2em 0 0;
border-right: 0.6em solid goldenrod;
z-index: -1;
}
For the body to add some light:
.body::before,
.body::after {
content: '';
position: absolute;
width: 5em;
height: 5em;
border: 0.6em solid transparent;
border-radius: 50%;
border-left-color: white;
}
.body::before {
transform: rotate(40deg);
top: 1em;
left: 1em;
}
.body::after {
bottom: 1em;
right: 1em;
transform: rotate(210deg);
}
Custom animation effects:
@keyframes bake {
0%, 20% {
transform: translateY(0);
}
80%, 100% {
transform: translateY(6em);
}
}
Finally, the animation effect applied to the handle and bread:
.handle {
animation: bake 3s infinite alternate;
}
.toast {
animation: bake 3s infinite alternate;
}
We're done!