Join Our Telegram Channel Contact Us Join Now!
Ad

Generate Link


Custom Dropdown Select Menu in HTML CSS & JavaScript

CSS Select Menu Custom Menu custom select menu Dropdown Select Menu HTML and CSS HTML CSS JavaScript HTML Select Menu Select Menu

Custom Dropdown Select Menu in HTML CSS & JavaScript

Custom Dropdown Select Menu in HTML CSS & JavaScript

 

# To create a Custom Dropdown Select Menu using JavaScript, you can use a combination of HTML, CSS, and JavaScript to create a Custom Dropdown Select Menu and apply a tilt effect to it. Here's an example:


1. First, create a container element in HTML for the Dropdown Menu:

                
<div class="container">
    <div class="dropdown" id="dropdown-content">
       <button class="dropdown_button" id="dropdown-btn">
          <i class="ri-user-3-line dropdown__icon"></i>
          <span class="dropdown__name">My profile</span>

          <div class="dropdown__icons">
             <i class="ri-arrow-down-s-line dropdown__arrow"></i>
             <i class="ri-close-line dropdown__close"></i>
          </div>
       </button>
       <ul class="dropdown__menu">
          <li class="dropdown__item">
             <i class="ri-message-3-line dropdown__icon"></i>
             <span class="dropdown__name">Messages</span>
          </li>
          <li class="dropdown__item">
             <i class="ri-lock-line dropdown__icon"></i>
             <span class="dropdown__name">Accounts</span>
          </li>
          <li class="dropdown__item">
             <i class="ri-settings-3-line dropdown__icon"></i>
             <span class="dropdown__name">Settings</span>
          </li>
       </ul>
    </div>
 </div>
            

2. Next, add some CSS to create a Dropdown Menu and position the container in the center:

                
/*=============== GOOGLE FONTS ===============*/
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&display=swap");

/*=============== VARIABLES CSS ===============*/
:root {
  /*========== Colors ==========*/
  /*Color mode HSL(hue, saturation, lightness)*/
  --first-color: hsl(0, 72.1%, 55.1%);
  --text-color: hsl(225, 52%, 30%);
  --body-color: linear-gradient(180deg, #FFFAFA, #fc9f9f);
  --container-color: hsl(225, 75%, 97%);

  /*========== Font and typography ==========*/
  /*.5rem = 8px | 1rem = 16px ...*/
  --body-font: "Montserrat", sans-serif;
  --normal-font-size: 1rem;
}

/*=============== BASE ===============*/
* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

body,
button {
  font-family: var(--body-font);
  font-size: var(--normal-font-size);
  color: var(--text-color);
}

ul {
  list-style: none;
}

.container {
  height: 100vh;
  display: grid;
  place-items: center;
  background: var(--body-color);
}

.dropdown {
  position: relative;
  width: max-content;
  transform: translateY(-5rem);
}

.dropdown_button,
.dropdown__item {
  display: flex;
  align-items: center;
  column-gap: .5rem;
}
.dropdown_button{
  border: none;
  outline: none;
  background-color: var(--container-color);
  padding: 1.25rem;
  border-radius: .75rem;
  cursor: pointer;
}
.dropdown__icon,
.dropdown__icons{
  font-size: 1.25rem;
  color: var(--first-color);
}
.dropdown__name{
  font-weight: 500;
}

.dropdown__icons{
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}

.dropdown__arrow,
.dropdown__close{
  position: absolute;
  transition: opacity .1s, transform .4s;
}

.dropdown__close{
  opacity: 0;
}

.dropdown__menu{
  background: var(--container-color);
  padding: 1rem 1.25rem;
  border-radius: .75rem;
  display: grid;
  row-gap: 1.5rem;
  position: absolute;
  width: 100%;
  left: 0;
  top: 4.5rem;
  transform: scale(.1);
  transform-origin: 10rem -2rem;
  pointer-events: none;
  transition: opacity .4s, transform .4s;
  opacity: 0;
}
.dropdown__item{
  cursor: pointer;
  transition: color .3s;
}
.dropdown__item:hover{
  color: var(--first-color);
}

.show-dropdown .dropdown__close{
  opacity: 1;
  transform: rotate(-180deg);
}
.show-dropdown .dropdown__arrow{
  opacity: 0;
  transform: rotate(-180deg);
}
.show-dropdown .dropdown__menu{
  opacity: 1;
  transform: scale(1);
  pointer-events: initial;
}
            

3. And, Add a Icon CSS in HTML for the Dropdown Menu:

                
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.2.0/fonts/remixicon.css" rel="stylesheet" >

            

4. Use JavaScript to create a Dropdown Menu Animation element inside the container:

                
const showDropdown = (content, button) => {
    const dropdowncont = document.getElementById(content),
       dropdownbtn = document.getElementById(button)
 
    dropdownbtn.addEventListener("click", () => {
       dropdowncont.classList.toggle("show-dropdown")
    })
 }
 showDropdown('dropdown-content', 'dropdown-btn') 
            

# Custom Dropdown in JavaScript HTML and CSS For Full Code 👇

 

 

* Hello buddy, I hope you are doing great and creating awesome projects. Today I have brought a useful project for you. In this project, you will learn to create `Custom Dropdown Select Menu` using HTML CSS, and JavaScript. Yeah, HTML also provides us a select menu with the dropdown feature, but we will you will learn to make it more beautiful and fascinating.

Rate this article

Loading...

Post a Comment


Continue


© code web 4u. All rights reserved.

Cookies Consent

This website uses cookies to ensure you get the best experience on our website.

Cookies Policy

We employ the use of cookies. By accessing Lantro UI, you agreed to use cookies in agreement with the Lantro UI's Privacy Policy.

Most interactive websites use cookies to let us retrieve the user’s details for each visit. Cookies are used by our website to enable the functionality of certain areas to make it easier for people visiting our website. Some of our affiliate/advertising partners may also use cookies.