<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Custom Select</title>
</head>
<body>

<div class="custom-select-wrapper" onclick="toggleDropdown()">
  <div class="selected-option">Categories</div>
  <img src="/src/assets/icons/CARET_DOWN.svg" alt="" class="custom-select-arrow">
  <div class="options">
    <div class="option" onclick="selectOption(event, 'Option 1')">Option 1</div>
    <div class="option" onclick="selectOption(event, 'Option 2')">Option 2</div>
    <div class="option" onclick="selectOption(event, 'Option 3')">Option 3</div>
  </div>
</div>
</body>
</html>
:root {
  --blue-500: #3AB8EB;
  --orange-500: #F9784B;
  --yellow-500: #FDBF0F;
  --gray-800: #3D3C3C;
  --gray-600: #676767;
  --white: #FFFFFF;
}

body {
  font-family: 'Syne', sans-serif;
}

.custom-select-wrapper {
  position: relative;
  width: 302px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s linear 0.1s;
  font-family: var(--syne);
  font-weight: 400;
  color: var(--gray-800);
  font-size: 16px;
}

.custom-select-wrapper:hover .selected-option {
  background-color: var(--yellow-500);
}
.custom-select-wrapper::after {
  content: '';
  width: 100%;
  height: 50px;
  background: var(--orange-500);
  border-radius: 20px;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: -1;
}

.custom-select {
  position: relative;
  height: 50px;
  display: flex;
  justify-content: space-between;
  padding: 0 30px 0 30px;
  width: 302px;
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  border: 2px solid var(--gray-800);
  z-index: 1;
}


.selected-option {
  cursor: pointer;
  width: 100%;
  height: 50px;
  z-index: 5;
  background: #fff;
  border-radius: 20px;
  border: 2px solid var(--gray-800);
  overflow: hidden;
}

.options {
  position: absolute;
  top: 100%;
  min-width: 302px;
  background-color: #fff;
  border-right: 2px solid var(--gray-800);
  border-left: 2px solid var(--gray-800);
  border-bottom: 2px solid var(--gray-800);
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  padding-top: 35px;
  z-index: 1;
  margin-top: -25px;
}

.option {
  cursor: pointer;
  display: flex;
  justify-content: left;
  padding-left: 22px;
  align-items: center;
  height: 45px;
  background-color: var(--white);
}

.custom-select-wrapper.open .selected-option {
  background-color: var(--yellow-500);
}

.option:hover {
  background-color: var(--blue-500);
  border-top: 2px solid var(--gray-800);
  border-bottom: 2px solid var(--gray-800);
}

.option:last-child {
  border-bottom-color: transparent;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
}
const wrapper = document.querySelector('.custom-select-wrapper');
const optionsContainer = wrapper.querySelector('.options');
const selectedOption = wrapper.querySelector('.selected-option');
const arrow = wrapper.querySelector('.custom-select-arrow');

function toggleDropdown() {
  wrapper.classList.toggle('open');
  if (wrapper.classList.contains('open')) {
    optionsContainer.style.display = 'block';
  } else {
    optionsContainer.style.display = 'none';
  }
}

function selectOption(event, option) {
  selectedOption.textContent = option;
  wrapper.classList.remove('open');
  optionsContainer.style.display = 'none';
  event.stopPropagation();
}

document.addEventListener('click', (event) => {
  if (!wrapper.contains(event.target)) {
    wrapper.classList.remove('open');
    optionsContainer.style.display = 'none';
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.