<label for="mood-picker" class="inclusively-hidden">Select a mood</label>
<select id="mood-picker">
<div class="items">
<option>👍</option>
<option>😂</option>
<option>😍</option>
<option>😢</option>
<option>😡</option>
</div>
</select>
@layer presentation, demo;
@layer demo {
:root {
--selected-color: oklch(99% 0.44 280);
--light-color: oklch(90% 0.49 269);
/* for body bg */
--bg-color: oklch(90% 0.37 274);
--bg-color-center: oklch(99% 0.17 285);
@supports (interpolate-size: allow-keywords) {
interpolate-size: allow-keywords;
}
}
select {
position: relative;
display: flex;
width: 64px;
height: 64px;
padding: 0;
place-items: center;
justify-content: center;
font-size: 2rem;
line-height: 1;
text-align: center;
background: var(--selected-color);
border: none;
border-radius: 50%;
aspect-ratio: 1;
appearance: none;
@supports (appearance: base-select) {
appearance: base-select;
}
&::picker-icon {
display: none;
}
}
/* currently using a point-event hack for touch-devices */
@supports (appearance: base-select) {
select::picker(select) {
position: absolute;
inset-block: anchor(top) anchor(bottom);
z-index: auto;
display: none;
width: 64px;
height: 64px;
padding: 0;
background: var(--light-color);
border: 0;
border-radius: 60px;
box-shadow: oklch(73% 0.39 280 / 0%) 0px 10px 50px;
overflow: clip;
appearance: base-select;
transition: width 0.5s ease-out, height 0.5s ease-out,
box-shadow 0.5s ease-out, display 0.5s, overlay 0.5s,
pointer-events 0.5s;
transition-behavior: allow-discrete;
@media (max-width: 600px) {
inset-block: anchor(top) auto;
}
}
select:open::picker(select) {
display: flex;
width: auto;
height: auto;
box-shadow: oklch(73% 0.39 280 / 58%) 0px 10px 50px;
pointer-events: auto;
@starting-style {
width: 64px;
height: 64px;
pointer-events: none;
}
}
}
select .items {
position: relative;
display: flex;
align-items: stretch;
transform-origin: 2% center;
font-size: 2rem;
line-height: 1;
border-radius: 60px;
overflow: auto;
scrollbar-width: none;
@media (max-width: 600px) {
flex-direction: column;
}
@media screen and (max-width: 600px) and (max-height: 455px) {
overflow-x: hidden;
scrollbar-width: thin;
}
}
@keyframes wiggle {
0% {
transform: rotate(10deg);
}
25% {
transform: rotate(-10deg);
}
50% {
transform: rotate(20deg);
}
75% {
transform: rotate(-5deg);
}
100% {
transform: rotate(0deg);
}
}
option {
position: relative;
display: flex;
flex: 0 0 64px;
min-width: 64px;
min-height: 65px;
padding: 0 1rem;
align-items: center;
font-size: 2rem;
line-height: 1;
background: var(--light-color);
cursor: pointer;
transition: background 0.4s;
@media (max-width: 600px) {
justify-content: center;
}
&:first-child {
border-radius: 60px 0 0 60px;
@media (max-width: 600px) {
border-radius: 60px 60px 0 0;
}
}
&:last-child {
border-radius: 0 60px 60px 0;
@media (max-width: 600px) {
border-radius: 0 0 60px 60px;
}
}
&:is(:hover, :focus-visible) span {
animation: wiggle 2s ease-out infinite;
}
&:checked {
position: sticky;
inset-block: 0;
inset-inline-end: 0;
z-index: 1;
background: var(--selected-color);
@media (max-width: 600px) {
inset-block: auto 0;
inset-inline: 0;
}
}
&::checkmark {
display: none;
}
@media (max-width: 500px) {
padding: 0.5rem;
}
}
}
@layer presentation {
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
position: relative;
display: flex;
min-height: 100vh;
margin: 0;
padding: 0;
flex-direction: column;
place-content: center;
place-items: center;
background-image: radial-gradient(
closest-corner circle at 50% 50% in oklab,
var(--bg-color-center) 0%,
var(--bg-color)
);
@media (max-height: 650px) {
place-content: start;
padding-top: 20px;
}
}
.inclusively-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);
white-space: nowrap;
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.