Feedback Rating Component Animation

Feedback Rating Component Animation

Hello Coders! Welcome to CSS Animation Blog. In this, we're going to see how to create Feedback Component which changes the emoji whenever you give a relevant star. Feedback is most important which allows an organization to identify mistakes and correct them in order to provide a better service or product. This is an example of a feedback rating component which enables the user to participate and rate the feedback.

screen-capture.gif

That being said, let us get started.

Step - 1: Like always, create 2 files - index.html and style.css.

Step - 2: Copy the below HTML code and paste it into your code editor.

HTML


<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Feedback Rating Component</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'>
  <link rel="stylesheet" href="style.css">

</head>
<body>

<form id="form">
  <fieldset class="stars">
    <input type="radio" name="stars" id="star1" 
        ontouchstart="ontouchstart"/>
    <label class="fa fa-star" for="star1"></label>
    <input type="radio" name="stars" id="star2" 
        ontouchstart="ontouchstart"/>
    <label class="fa fa-star" for="star2"></label>
    <input type="radio" name="stars" id="star3" 
        ontouchstart="ontouchstart"/>
    <label class="fa fa-star" for="star3"></label>
    <input type="radio" name="stars" id="star4" 
        ontouchstart="ontouchstart"/>
    <label class="fa fa-star" for="star4"></label>
    <input type="radio" name="stars" id="star5" 
        ontouchstart="ontouchstart"/>
    <label class="fa fa-star" for="star5"></label>
    <input type="radio" name="stars" id="star-reset"/>
    <label class="reset" for="star-reset">reset</label>
    <figure class="face"><i></i><i></i>
      <u>
        <div class="cover"></div>
      </u>
    </figure>
  </fieldset>
</form>

</body>
</html>

Step - 3: Below is the CSS code for styling.

CSS


html, body {
    height: 100%;
    padding: 0;
    margin: 0;
}
body {
    overflow: hidden;
    background: #f6f7fc;
}
#form {
    display: flex;
    flex-direction: column-reverse;
    justify-content: center;
    align-items: center;
    max-width: 800px;
    height: 100%;
    margin: auto;
}
[class*="fontawesome-"]:before {
    font-family: 'FontAwesome', sans-serif;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
    width: 100%;
    height: 100%;
}
.reset {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    margin: auto;
    padding: 12px 24px;
    color: #4d4d4d;
    background: #f6f7fc;
    border-radius: 60px;
    font-family: "Helvetica", sans-serif;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    outline: none;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
}
.reset:hover {
    background: #fbc416;
}
input,label {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
.stars {
    position: relative;
}
.stars input {
    display: none;
}
.stars input:checked~label:not(.reset) {
    -webkit-animation: wobble 0.8s ease-out;
    animation: wobble 0.8s ease-out;
    color: #fbc416;
}
.stars input:checked:not(#star-reset)~label.reset {
    display: block;
}
.stars label:not(.reset) {
    display: inline-block;
    float: right;
    position: relative;
    width: 40px;
    height: 40px;
    font-size: 40px;
    padding: 2px;
    cursor: pointer;
    color: #3d3d3d;
    transition: color 0.1s ease-out;
    z-index: 10;
}
.face {
    position: relative;
    width: 200px;
    background: f6f7fc;
    border: 6px solid #f0f0f0;
    border-radius: 100%;
    margin: 80px 0 50px;
    transition: box-shadow 0.4s ease-out;
}
.face:after {
    content: "";
    display: block;
    padding-bottom: 100%;
}
i {
    position: absolute;
    top: 50%;
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 100%;
    background: #f0f0f0;
}
i:nth-child(1) {
    left: 30%;
}
i:nth-child(2) {
    right: 30%;
}
u {
    position: absolute;
    right: 0;
    bottom: 25%;
    left: 0;
    margin: auto;
    width: 24px;
    height: 24px;
    text-decoration: none;
    border: 6px solid #f0f0f0;
    border-radius: 100%;
}
u:before,
u:after {
    content: "";
    position: absolute;
    top: 15px;
    width: 6px;
    height: 6px;
    background: #f0f0f0;
    border-radius: 60px 60px 0 0;
    z-index: 2;
}
u:before {
    left: -5px;
    -webkit-transform: rotate(-32deg);
    transform: rotate(-32deg);
}
u:after {
    right: -5px;
    -webkit-transform: rotate(32deg);
    transform: rotate(32deg);
}
u .cover {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 100%;
    height: 100%;
    border: 6px solid white;
    background: white;
    -webkit-transform: translate(0, -12px);
    transform: translate(0, -12px);
}
input#star4:checked~.face u,
input#star2:checked~.face u {
    width: 36px;
}
input#star4:checked~.face u:before,
input#star4:checked~.face u:after,
input#star2:checked~.face u:before,
input#star2:checked~.face u:after {
    top: 18px;
    height: 10px;
}
input#star4:checked~.face u:before,
input#star2:checked~.face u:before {
    left: 0px;
    -webkit-transform: rotate(-66deg);
    transform: rotate(-66deg);
}
input#star4:checked~.face u:after,
input#star2:checked~.face u:after {
    right: 0px;
    -webkit-transform: rotate(66deg);
    transform: rotate(66deg);
}
input#star4:checked~.face u .cover,
input#star2:checked~.face u .cover {
    -webkit-transform: translate(0, -8px);
    transform: translate(0, -8px);
}
input#star5:checked~.face u,
input#star4:checked~.face u {
    -webkit-transform: rotate(180deg) translateY(-20px);
    transform: rotate(180deg) translateY(-20px);
}
input#star3:checked~.face u {
    width: 42px;
    height: 6px;
    background: #3d3d3d;
    border: none;
    border-radius: 60px;
    -webkit-transform: translateY(-4px);
    transform: translateY(-4px);
}
input#star3:checked~.face u:before,
input#star3:checked~.face u:after,
input#star3:checked~.face u .cover {
    display: none;
}
input:not(#star-reset):checked~.face {
    -webkit-animation: wobble 0.8s ease-out;
    animation: wobble 0.8s ease-out;
}
input:not(#star-reset):checked~.face,
input:not(#star-reset):checked~.face u {
    border-color: #3d3d3d;
}
input:not(#star-reset):checked~.face i,
input:not(#star-reset):checked~.face u:before,
input:not(#star-reset):checked~.face u:after {
    background: #3d3d3d;
}
input#star5:checked~.face {
    background-color: #fa5563;
}
input#star5:checked~.face u .cover {
    background: #fa5563;
    border-color: #fa5563;
}
input#star4:checked~.face {
    background-color: #fa824e;
}
input#star4:checked~.face u .cover {
    background: #fa824e;
    border-color: #fa824e;
}
input#star3:checked~.face {
    background-color: #fccd3f;
}
input#star2:checked~.face {
    background-color: #a0d77a;
}
input#star2:checked~.face u .cover {
    background: #a0d77a;
    border-color: #a0d77a;
}
input#star1:checked~.face {
    background-color: #6bca6c;
}
input#star1:checked~.face u .cover {
    background: #6bca6c;
    border-color: #6bca6c;
}
@-webkit-keyframes wobble {
    0% {
        -webkit-transform: scale(0.8);
        transform: scale(0.8);
    }

    20% {
        -webkit-transform: scale(1.1);
        transform: scale(1.1);
    }

    40% {
        -webkit-transform: scale(0.9);
        transform: scale(0.9);
    }

    60% {
        -webkit-transform: scale(1.05);
        transform: scale(1.05);
    }

    80% {
        -webkit-transform: scale(0.96);
        transform: scale(0.96);
    }

    100% {
        -webkit-transform: scale(1);
        transform: scale(1);
    }
}
@keyframes wobble {
    0% {
        -webkit-transform: scale(0.8);
        transform: scale(0.8);
    }

    20% {
        -webkit-transform: scale(1.1);
        transform: scale(1.1);
    }

    40% {
        -webkit-transform: scale(0.9);
        transform: scale(0.9);
    }

    60% {
        -webkit-transform: scale(1.05);
        transform: scale(1.05);
    }

    80% {
        -webkit-transform: scale(0.96);
        transform: scale(0.96);
    }

    100% {
        -webkit-transform: scale(1);
        transform: scale(1);
    }
}

And that's it. You're done.

Let me know in the comments if you have any doubt related to this.

Follow @creocodigo for more projects and web related content.

If you find this useful, below are some other posts that I am sure you'll love