最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Styling a disabled range input - Stack Overflow

programmeradmin3浏览0评论

I'm have range inputs styled with

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 3px;
    background: #2C65FF;
    border-radius: 2px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
    background: #2C65FF;
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 3px;
    background: #2C65FF;
    border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 10px;
    width: 10px;
    background: white;
    margin-top: -14px;
}

input[type=range]::-moz-range-thumb {
    height: 10px;
    width: 10px;
    background: white;
}

I'd like to give them a "greyed out" style when they're disabled. Just tacking on a :disabled on to each of the existing selectors with a darkened background does not seem to be doing anything.

How can I style a disabled range input?

I'm have range inputs styled with

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 3px;
    background: #2C65FF;
    border-radius: 2px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
    background: #2C65FF;
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 3px;
    background: #2C65FF;
    border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 10px;
    width: 10px;
    background: white;
    margin-top: -14px;
}

input[type=range]::-moz-range-thumb {
    height: 10px;
    width: 10px;
    background: white;
}

I'd like to give them a "greyed out" style when they're disabled. Just tacking on a :disabled on to each of the existing selectors with a darkened background does not seem to be doing anything.

How can I style a disabled range input?

Share Improve this question asked Jan 28, 2020 at 0:26 kag0kag0 6,0648 gold badges41 silver badges70 bronze badges 2
  • This doesn't work? input[type="range"]:disabled { Probably needs the quotes. – Rob Moll Commented Jan 28, 2020 at 0:36
  • see my Answer below, its what you looking for – X3R0 Commented Jan 28, 2020 at 0:46
Add a ment  | 

1 Answer 1

Reset to default 8

you need to add on the other css props like this:


input[type=range]:disabled {
    /* Disabled Element */
}

input[type=range]:disabled::-webkit-slider-runnable-track {
    /* Disabled slider-runnable-track */
}

input[type=range]:disabled::-moz-range-track {
      /* Disabled slider-range-track */
}

input[type=range]:disabled::-webkit-slider-thumb {
    /* Disabled slider-thumb */
}

input[type=range]:disabled::-moz-range-thumb {
    /* Disabled slider-thumb */
}

Example: Link

notice

":disabled" followed by "::-propertyname"

发布评论

评论列表(0)

  1. 暂无评论