How to style a dropdown using CSS?
There are many ways to design <select> dropdown menu using CSS. Dropdown menu is mainly used to select an element from the list of elements.
Example 1: This example contains the dropdown CSS property to display the appearance of dropdown box. It contains the CSS property to set the dropdown background color, text-color, font-size, cursor pointer etc.
<!DOCTYPE html> <html> <head> <style> select { appearance: none; outline: 0; background: green; background-image: none; width: 100%; height: 100%; color: black; cursor: pointer; border:1px solid black; border-radius:3px; } .select { position: relative; display: block; width: 15em; height: 2em; line-height: 3; overflow: hidden; border-radius: .25em; padding-bottom:10px; } h1 { color:green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <div class="select"> <select name="slct" id="slct"> <option>Computer Science Subjects</option> <option value="1">Operating System</option> <option value="2">Computer Networks</option> <option value="3">Data Structure</option> <option value="4">Algorithm</option> <option value="5">C programming</option> <option value="6">JAVA</option> </select> </div> </center> </body> </html> |
Output:

Example 2: This example contains some CSS property to display the appearance of dropdown box where -webkit-, -moz- and -ms- used for browser support.
<!DOCTYPE html> <html> <head> <style> h1 { color:green; } select { -webkit-appearance: none; -moz-appearance: none; -ms-appearance: none; appearance: none; outline: 0; background: green; background-image: none; border:1px solid black; } .select { position: relative; display: block; width: 20em; height: 3em; line-height: 3; background: #2C3E50; overflow: hidden; border-radius: .25em; } select { width: 100%; height: 100%; margin: 0; padding: 0 0 0 .5em; color: #fff; cursor: pointer; } select::-ms-expand { display: none; } .select::after { content: '\25BC'; position: absolute; top: 0; right: 0; bottom: 0; padding: 0 1em; background: #34495E; pointer-events: none; } .select:hover::after { color: #F39C12; } <!-- For diffrent browsers --> .select::after { -webkit-transition: .25s all ease; -o-transition: .25s all ease; transition: .25s all ease; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <div class="select"> <select name="slct" id="slct"> <option>Computer Science Subjects</option> <option value="1">Operating System</option> <option value="2">Computer Networks</option> <option value="3">Data Structure</option> <option value="4">Algorithm</option> <option value="5">C programming</option> <option value="6">JAVA</option> </select> </div> </center> </body> </html> |
Output:

Recommended Posts:
- How to remove arrow in dropdown in Bootstrap ?
- How to get selected value in dropdown list using JavaScript ?
- How to avoid dropdown menu to close menu items on clicking inside ?
- How to style a checkbox using CSS?
- HTML | Style Tag
- How to create a style tag using JavaScript?
- AngularJS | ng-style Directive
- CSS | border-top-style Property
- CSS | outline-style Property
- HTML | DOM Style top Property
- HTML | DOM Style right Property
- CSS | font-style Property
- CSS | list-style Property
- CSS | border-style Property
- CSS | border-right-style Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



