<!DOCTYPE html> <html> <head> <style> .smiling-face{ width:200px; height:200px; background-color:yellow; border-radius:50%; position:relative; } .left-eye{ width:23%; height:20%; border-radius:45%; background-color:rgb(240,240,240); position:absolute; left:20%; top:20%; } .right-eye{ width:23%; height:20%; border-radius:45%; background-color:rgb(240,240,240); position:absolute; right:20%; top:20%; } .left-pupil,.right-pupil{ width:48%; height:45%; border-radius:50%; background-color:rgb(100,100,100); position:absolute; top:55%; /* 55 = 100 (total) - 45 (height) */ left:26%; /* 26 = 50 (half of total) - 24 (half of width) */ } .lip{ width:62.5%; height:25%; background-color:yellow; border-radius:50%; position:absolute; left:18.75%; /* 18.75 = (100-62.5)/2 */ top:45%; border:solid red; border-width:1px 0px 0px 0px; transform:rotateZ(0deg); -webkit-transform:rotateZ(0deg); /* for safari */ } </style> </head> <body> <div class="smiling-face"> <span class="left-eye"> <span class="left-pupil"> </span> </span> <span class="right-eye"> <span class="right-pupil"> </span> </span> <span class="lip"> </span> </div> </body> </html>
Run
×
Share