One
Two
Three
Mac 的option 样式无法定制, windows 只能改颜色和背景色。
.selectwrap { position: relative; /* imp */ width: fit-content; /* 和select 同宽 */ margin: 10px; } .selectwrap select { font-size: 24px; background: #e9e9e9; height: 58px; width: 500px; border-radius: 58px; padding: 0 20px; border: 0; outline: none; /* 去掉难看的聚焦边框 */ appearance: none; /* 隐藏本身的arrow */ } .selectwrap:after { width: 54px; height: 54px; border-radius: 50%; border: 2px solid #a8a8a8; content: ''; display: flex; background: url(img/select_arrow.svg) no-repeat center; background-size: 50%; position: absolute; top: 0; right: 0; z-index: 0; pointer-events: none; /* imp 没有这个 遮盖挡住点不动, 透明和pointer-events:none; 在一起才算绝对透明 */ }
黄药师
欧阳锋
段智兴
洪七公
周伯通
#s2 select { outline: none; border: 2px solid black; border-radius: 8px; margin: 10px; } #s2 option { background: orange; cursor: pointer; padding: 4px; color: white; } #s2 option:first-child { background: red; } #s2 option:nth-child(2) { background: blue; } #s2 option:nth-child(3) { background: green; } #s2 option:nth-child(4) { background: purple; } #s2 option:hover { background: magenta; } #s2 option:checked { background: black; }
利用 js 造
One
Two
Three
.mb-select { position: relative; /* imp */ width: fit-content; /* 和select 同宽 */ margin: 10px; z-index: 1; } .mb-select[data-drop="true"] { z-index: 2; /* 防止相邻下拉杠层级覆盖 */ } .mb-select input { font-size: 24px; background: #e9e9e9; height: 58px; border-radius: 58px; width: 100%; padding: 0 20px; border: 2px solid #e9e9e9; outline: none; /* 去掉难看的聚焦边框 */ cursor: pointer; box-sizing: border-box; } .mb-select:after { width: 58px; height: 58px; box-sizing: border-box; border-radius: 50%; border: 2px solid #a8a8a8; content: ''; display: flex; background: url(img/select_arrow.svg) no-repeat center; background-size: 50%; position: absolute; top: 0; right: 0; z-index: 0; pointer-events: none; /* imp 没有这个 遮盖挡住点不动, 透明和pointer-events:none; 在一起才算绝对透明 */ } .mb-select[data-drop="true"] input { border-color: #a8a8a8; } .mb-select .option-wrap { visibility: hidden; width: 100%; box-sizing: border-box; /* imp */ cursor: pointer; position: absolute; z-index: -1; background: #e9e9e9; border: 2px solid #a8a8a8; margin-top: -27px; border-radius: 0 0 27px 27px; padding: 37px 0 20px; } .mb-select .option-wrap option { line-height: 2; font-size: 24px; text-align: center; } .mb-select .option-wrap option:hover { background: rgba(255,255,255,0.5); } .mb-select[data-drop="true"] .option-wrap { visibility: visible; animation: show-mb-select-drop 3s cubic-bezier(0,.52,.35,.99) forwards; } @keyframes show-mb-select-drop { 0% { max-height: 0px; } 100% { max-height: 500px; } }
SINCE 2022 ©
markbuild