JSFiddle - React, Tailwind, and code Playground
by rbrousla
HTML
<div id="robot">
<div id="head">
<div class="eye" id="righteye"></div>
<div class="eye" id="lefteye"></div>
<div id="nose"></div>
<div id="mouth"></div>
</div>
<div class="arm" id="rightarm"></div>
<div id="body"><p>I <3 JS!</p></div>
<div class="arm" id="leftarm"></div>
</div>
CSS
body {
font-family: "Comic Sans MS", cursive, sans-serif;
}
p {
font-size: 3em;
}
.eye {
background-color:blue;
width:30%;
height:30%;
border-radius: 50%;
}
.arm {
background-color: #cacaca;
position: absolute;
top: 35%;
width: 3%;
height: 40%;
}
#head {
width:30%;
height:30%;
border-radius: 15%;
background-color: #dadada;
position: absolute;
left: 33%;
top: 5%;
}
#righteye {
position: absolute;
left: 20%;
top: 20%;
}
#lefteye {
position: absolute;
left: 60%;
top: 20%;
}
#nose {
position: absolute;
left: 45%;
top: 50%;
width: 10%;
height: 10%;
background-color: black;
}
#mouth {
position: absolute;
width: 65%;
height: 15%;
left: 20%;
top: 70%;
background-color: red;
}
#body {
position: absolute;
left: 25%;
top: 35%;
width: 45%;
height: 55%;
background-color: #dadada;
text-align:center;
padding-top: 30px;
}
#rightarm {
position:absolute;
left:20%;
}
#leftarm {
position: absolute;
left: 70%;
width: 25%;
height: 5%;
}
JavaScript
document.getElementById("lefteye").style.backgroundColor = "purple";
document.getElementById("head").style.transform = "rotate(15deg)";
document.getElementById("body").style.border = "2px black solid";
document.getElementById("mouth").style.borderRadius = "4px";
document.getElementById("righteye").style.border = "4px yellow dotted";
document.getElementById("leftarm").style.backgroundColor = "#ff00ff";
document.getElementById("body").style.color = "#ff0000";
document.getElementById("head").style.borderTop = "5px black solid";
/*
Now it's your turn!
Can you figure out how to make the following changes
with JavaScript?
*/
// tilt Douglas's head to the other side
// make Douglas's nose round
// make Douglas's right arm green
// make Douglas's lips pink
/*
Solutions
*/
// document.getElementById("head").style.transform = "rotate(-15deg)";
// document.getElementById("nose").style.borderRadius = "50%";
// document.getElementById("rightarm").style.backgroundColor = "green";
// document.getElementById("mouth").style.backgroundColor = "pink";