How to make emojis with CSS
The emoji should be used to check the feedback of a user for the website. These emojis represent the emotions of a user for your website.
<style>
.smiling-face{
width:200px;
height:200px;
background-color:yellow;
border-radius:50%;
position:relative;
}
.left-eye{
width:23%;
height:20%;
border-radius:50%;
background-color:rgb(240,240,240);
position:absolute;
left:20%;
top:20%;
}
.right-eye{
width:23%;
height:20%;
border-radius:50%;
background-color:rgb(240,240,240);
position:absolute;
right:20%;
top:20%;
}
.left-pupil{
width:48%;
height:45%;
border-radius:50%;
background-color:rgb(100,100,100);
position:absolute;
top:55%;
left:26%;
}
.right-pupil{
width:48%;
height:45%;
border-radius:50%;
background-color:rgb(100,100,100);
position:absolute;
top:55%;
left:26%;
}
.lip{
width:52.5%;
height:25%;
background-color:yellow;
border-radius:50%;
position:absolute;
left:23.75%;
top:45%;
border:solid red;
border-width:2px 0px 0px 0px;
-webkit-transform:rotateZ(0deg);
transform:rotateZ(0deg);
}
.smiling-face:hover .lip{
-webkit-transition-timing-function:ease-in;
-webkit-transition:transform 0.01s;
-webkit-transition-delay:2s;
-webkit-transform:rotateZ(180deg);
transition-timing-function:ease-in;
transition:transform 0.01s;
transition-delay:2s;
transform:rotateZ(180deg);
}
.smiling-face:hover .left-pupil, .smiling-face:hover .right-pupil{
-webkit-transition-property:top,width,height;
-webkit-transition-duration:1s,1s,1s;
-webkit-transition-delay:0s,1s,1s;
transition-property:top,width,height;
transition-duration:1s,1s,1s;
transition-delay:0s,1s,1s;
top:27.5%;
width:46%;
height:43%;
}
</style>
<p>Hover over the image to see the animation effect.</p>
<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>
.smiling-face
Define a class .smiling-face for the face.
<style>
.smiling-face{
width:200px;
height:200px;
background-color:yellow;
border-radius:50%;
position:relative;
}
</style>position:relative; is necessary to position the descendent elements relative to this element.
Tip: Remember that the percentage values of length of the child elements are calculated with respect to the parent element.
.left-eye
Now define a class .left-eye for the left-eye. It is a child of the .face class element.
<style>
.left-eye{
width:23%;
height:20%;
background-color:rgb(240,240,240);
border-radius:45%;
position:absolute;
left:20%;
top:20%;
}
</style>position:absolute; property defines position of the left-eye (using left and top properties).
The width should be greater than height.
23% of width and 20% of height are the percentage values with respect to the parent element (.face).
45% value converts the rectangular shape into a elliptical shape
.right-eye
The dimesions of the left-eye should be the same as right-eye. Define .right-eye class for the right-eye. It is also a child of the .smiling-face class element.
<style>
.right-eye{
right:20%;
top:20%;
}
</style>The properties of the right-eye are the same as left-eye. But there is only one difference. The left property should be replaced by the right property.
left-pupil
.left-pupil class name is specified for the left-pupil. Now, it is a child of the left-eye.
<style>
.left-pupil{
width:48%;
height:45%;
background-color:rgb(100,100,100);
border-radius:50%;
position:absolute;
top:55%; /* 55 = 100 (total) - 45 (height) */
left:26%; /* 26 = 50 (half of total) - 24 (half of width) */
}
</style>55% value represents the distance between the top side of the left-pupil and and top side of the left-eye.
26% value represents the distance between the left side of the left-pupil and and left side of the left-eye.
width is greater than height to make it elliptical.
right-pupil
.right-pupil class name is specified for the right-pupil. It has the same properties as the .left-pupil class has. But it is a child of the .right-eye element.
lip
.lip class element represents lip of the emoji. It is a child of the .smiling-face class element.
<style>
.lip{
width:62.5%;
height:25%;
background-color:yellow;
border-radius:50%;
border:solid red;
border-width:1px 0px 0px 0px;
transform:rotateZ(0deg);
position:absolute;
left:18.75%; /* 18.75 = (100-62.5)/2 */
top:45%;
}
</style>position:absolute; property must be present to align it at the center.
When a user hovers the mouse over the emoji, the emoji should present a smiling view. The following properties should be changed.
<style>
.smiling-face:hover .lip{
transition-timing-function:ease-in;
transition:transform 0s;
transition-delay:2s;
transform:rotateZ(180deg);
}
</style>When a user hovers the mouse over the .smiling-face class element, the .lip class element changes its properties.
Similarly, the properties of .left-pupil and .right-pupil are changed.
<style>
.smiling-face:hover .left-pupil, .smiling-face:hover .right-pupil{
transition-property:top,width,height;
transition-duration:1s,1s,1s;
transition-delay:0s,1s,1s;
top:27.5%;
width:46%;
height:43%;
}
</style>Same is the case with the .right-pupil element.