Programming/Html

[Html] select element ์—์„œ dropdown icon ๋ฐ”๊พธ๋Š” ๋ฐฉ๋ฒ•

yuri lee 2024. 4. 23. 20:09
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. select element ์—์„œ dropdown icon ๋ฐ”๊พธ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :) 

 

How to solve problem

<select class="custom-select">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
</select>
/* Hide the default dropdown arrow */
.custom-select {
  appearance: none; /* For Firefox */
  -webkit-appearance: none; /* For Chrome, Safari, Opera */
  -moz-appearance: none; /* For Firefox */
  background-image: url('custom-dropdown-icon.png'); /* Custom arrow icon */
  background-position: right center;
  background-repeat: no-repeat;
  padding-right: 20px; /* Adjust according to your icon's width */
}

/* Style the dropdown icon */
.custom-select::-ms-expand {
  display: none; /* For IE 11 */
}

 

  • appearance: none;, webkit-appearance: none;, moz-appearance: none ์†์„ฑ์„ ์‚ฌ์šฉํ•ด์„œ default dropdown arrow๋ฅผ ์ˆจ๊ฒจ์ค๋‹ˆ๋‹ค. 
  • background-image ์†์„ฑ์„ ํ†ตํ•ด ์ปค์Šคํ…€ ํ•˜๊ณ ์ž ํ•˜๋Š” icon์„ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. 
  • background-position, background-repeat, padding-right ์„ ์‚ฌ์šฉํ•˜์—ฌ arrow icon ์œ„์น˜๋ฅผ ์กฐ์ •ํ•ด์ค๋‹ˆ๋‹ค. 
  • IE11 ๋ธŒ๋ผ์šฐ์ €์—์„œ ::-ms-expand ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ default arrow๋ฅผ ์ˆจ๊น๋‹ˆ๋‹ค. 
๋ฐ˜์‘ํ˜•