28
loading...
This website collects cookies to deliver better user experience
fieldset
but within that there will be a block of input
s (radio buttons specifically), a block of label
s inside a div
and a block of div
s that we'll call tooltips as we're going to have a tooltip to show which mood we have selected.<input name="rating" value="1" type="radio" id="rating1">
<label title="Sad" aria-describedby="SadTooltip" for="rating1">
<span aria-hidden="true" class="star">😞</span>
</label>
<div class="tooltip" id="SadTooltip">😞 Sad</div>
color: transparent;
which means our unicode characters will be invisible and transform: scale(0.2);
which mean the label will appear tiny..emotion-rating .labels>label {
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
position: relative;
line-height: 1em;
text-align: center;
transform: scale(0.2);
color: transparent;
transition: all 350ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
background-color: #F08080;
height: 1.75em;
width: 1.75em;
border-radius: 1em;
user-select: none;
}
.emotion-rating .labels>label:hover {
transform: scale(0.6);
color: initial;
z-index: 1;
}
.emotion-rating .tooltip {
font-size: 0.75em;
height: 0;
text-align: left;
box-sizing: border-box;
border-radius: 15px;
background-color: white;
opacity: 0;
transform: translateY(-50%);
position: relative;
transition-property: opacity, transform;
transition: 0 cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
/* label for input before currently checked */
#rating3:checked~.labels>[for=rating2] {
transform: scale(1);
color: initial;
z-index: 1;
}
/* emoji for input before currently checked */
#rating3:checked~.labels>[for=rating2] .star {
opacity: 0.8;
}
/* label for input currently checked */
#rating3:checked~.labels>[for=rating3] {
transform: scale(1.4);
color: initial;
z-index: 0;
}
/* label for input after currently checked */
#rating3:checked~.labels>[for=rating4] {
transform: scale(1);
color: initial;
z-index: 1;
}
/* emoji for input after currently checked */
#rating3:checked~.labels>[for=rating4] .star {
opacity: 0.8;
}
/* tooltip related to checked input */
#rating3:checked~#NeutralTooltip {
display: block;
opacity: 1;
transform: translate(0);
height: auto;
padding: 0.4em 0.8em;
margin-top: 0.8em;
border: 4px solid #F08080;
transition-duration: 350ms;
transition-delay: 150ms;
}
prefers-reduced-motion
media query is super important.@media (prefers-reduced-motion) {
.emotion-rating .tooltip {
transform: translate(0);
}
.emotion-rating .labels>label {
transform: scale(0.6) !important;
color: initial;
transition-duration: 0ms;
}
.emotion-rating .labels>label .star {
opacity: 0.8;
}
#rating1:checked~.labels>[for=rating1] {
transform: scale(1) !important;
}
#rating2:checked~.labels>[for=rating2] {
transform: scale(1) !important;
}
#rating3:checked~.labels>[for=rating3] {
transform: scale(1) !important;
}
#rating4:checked~.labels>[for=rating4] {
transform: scale(1) !important;
}
#rating5:checked~.labels>[for=rating5] {
transform: scale(1) !important;
}
}