• <tfoot id='Iwe5K'></tfoot>
    <i id='Iwe5K'><tr id='Iwe5K'><dt id='Iwe5K'><q id='Iwe5K'><span id='Iwe5K'><b id='Iwe5K'><form id='Iwe5K'><ins id='Iwe5K'></ins><ul id='Iwe5K'></ul><sub id='Iwe5K'></sub></form><legend id='Iwe5K'></legend><bdo id='Iwe5K'><pre id='Iwe5K'><center id='Iwe5K'></center></pre></bdo></b><th id='Iwe5K'></th></span></q></dt></tr></i><div id='Iwe5K'><tfoot id='Iwe5K'></tfoot><dl id='Iwe5K'><fieldset id='Iwe5K'></fieldset></dl></div>

    <small id='Iwe5K'></small><noframes id='Iwe5K'>

    1. <legend id='Iwe5K'><style id='Iwe5K'><dir id='Iwe5K'><q id='Iwe5K'></q></dir></style></legend>

        <bdo id='Iwe5K'></bdo><ul id='Iwe5K'></ul>

        带有中间点标记的范围输入(滑块)

        时间:2024-04-18
        <tfoot id='uLEd1'></tfoot>

          <bdo id='uLEd1'></bdo><ul id='uLEd1'></ul>
            • <small id='uLEd1'></small><noframes id='uLEd1'>

                <legend id='uLEd1'><style id='uLEd1'><dir id='uLEd1'><q id='uLEd1'></q></dir></style></legend>
                  <tbody id='uLEd1'></tbody>

                  <i id='uLEd1'><tr id='uLEd1'><dt id='uLEd1'><q id='uLEd1'><span id='uLEd1'><b id='uLEd1'><form id='uLEd1'><ins id='uLEd1'></ins><ul id='uLEd1'></ul><sub id='uLEd1'></sub></form><legend id='uLEd1'></legend><bdo id='uLEd1'><pre id='uLEd1'><center id='uLEd1'></center></pre></bdo></b><th id='uLEd1'></th></span></q></dt></tr></i><div id='uLEd1'><tfoot id='uLEd1'></tfoot><dl id='uLEd1'><fieldset id='uLEd1'></fieldset></dl></div>
                • 本文介绍了带有中间点标记的范围输入(滑块)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想要一个使用 HTML5 的滑块,如下所示:我可以在哪里显示值.我试过下面的代码:

                  I want a slider using HTML5 like this: where I can display the value. I have tried the below code:

                  <input type=range min=0 max=100 value=50 step=1 list=tickmarks>
                      <datalist id=tickmarks>
                          <option value="0 to 20">0</option>
                          <option>20</option>
                          <option>40</option>
                          <option>60</option>
                          <option>80</option>
                          <option>100</option>
                      </datalist>
                  

                  但似乎没有任何效果.有什么想法吗?

                  But nothing seems to work. Any Idea?

                  推荐答案

                  你可以通过使用下面的代码来实现你想要的.我们在这里做的是:

                  You can sort of achieve what you want by using the below code. What we are doing here is:

                  • 使用线性梯度(重复)以所需的间隔生成线条
                  • 使用伪元素添加文本,然后使用 word-spacing 属性在它们之间提供所需的空间.对于 Chrome(Webkit 浏览器)容器不是必需的,示例中的注释代码就足够了,但 Firefox 需要容器.我认为 FF 中的行为是正确的,因为通常不希望 input 元素支持伪元素,因此最好保留容器以防未来
                  • Use a linear-gradient (repeating) to generate the lines at the required intervals
                  • Add the text using a pseudo-element and then give the required space in between them using the word-spacing property. For Chrome (Webkit browsers) the container is not required and the commented code in the sample is alone enough but Firefox requires to container. I think behavior in FF is the correct one because input elements generally aren't expected to support pseudo-elements and hence it is better to retain the container to be future-proof

                  注意事项:

                  • 此示例在 Chrome(44.0.2376.0 dev-m、42.0.2311.90 m)、Firefox (36.0.4)、Internet Explorer 11 和 Opera 28 上进行了测试.
                  • 我认为 repeating-linear-gradientlinear-gradient 的使用应该不是问题.
                  • This sample is tested on Chrome (44.0.2376.0 dev-m, 42.0.2311.90 m), Firefox (36.0.4), Internet Explorer 11 and Opera 28.
                  • I assume that the usage of repeating-linear-gradient or linear-gradient should not be an issue.

                  浏览器支持:

                  • 适用于范围输入 - Chrome 5+、Firefox 23+、IE 10+、Safari 3.1+、Opera 9+
                  • 用于重复渐变 - Chrome 10+(-webkit 前缀)、Firefox 3.6+(-moz 前缀)、IE 10+、Safari 5.1、Opera 11.6.

                  input[type='range'] {
                    box-sizing: border-box;
                    border: 0px solid transparent;
                    padding: 0px;
                    margin: 0px;
                    width: 210px;
                    height: 50px;
                    cursor: pointer;
                    background: -webkit-repeating-linear-gradient(90deg, #777, #777 1px, transparent 1px, transparent 40px) no-repeat 50% 50%;
                    background: -moz-repeating-linear-gradient(90deg, #777, #777 1px, transparent 1px, transparent 40px) no-repeat 50% 50%;
                    background: repeating-linear-gradient(90deg, #777, #777 1px, transparent 1px, transparent 40px) no-repeat 50% 50%;
                    background-size: 122px 25px;
                    font-size: 16px;
                  }
                  input[type='range'],
                  input[type='range']::-webkit-slider-runnable-track,
                  input[type='range']::-webkit-slider-thumb {
                    -webkit-appearance: none;
                  }
                  input[type='range']::-webkit-slider-runnable-track {
                    box-sizing: border-box;
                    width: 200px;
                    height: 5px;
                    border-radius: 2px;
                    background: #777;
                  }
                  input[type='range']::-moz-range-track {
                    box-sizing: border-box;
                    width: 200px;
                    height: 5px;
                    border-radius: 2px;
                    padding: 0px;
                    background: #777;
                  }
                  input[type='range']::-moz-range-thumb {
                    box-sizing: border-box;
                    padding: 0px;
                    height: 20px;
                    width: 10px;
                    border-radius: 2px;
                    border: 1px solid;
                    background: #EEE;
                  }
                  input[type='range']::-ms-track {
                    box-sizing: border-box;
                    width: 210px;
                    height: 5px;
                    border-radius: 2px;
                    padding: 0px;
                    background: #777;
                    color: #777;
                  }
                  input[type='range']::-webkit-slider-thumb {
                    box-sizing: border-box;
                    padding: 0px;
                    height: 20px;
                    width: 10px;
                    border-radius: 2px;
                    border: 1px solid;
                    margin-top: -8px;
                    background: #EEE;
                  }
                  input[type='range']::-ms-thumb {
                    box-sizing: border-box;
                    padding: 0px;
                    height: 20px;
                    width: 10px;
                    border-radius: 2px;
                    border: 1px solid;
                    background: #EEE;
                  }
                  input[type="range"]::-ms-fill-lower {
                    background: transparent;
                  }
                  input[type='range']:focus {
                    outline: none;
                  }
                  /*input[type='range']:after{
                    position: absolute;
                    content: '20 40 60 80';
                    padding: 25px 4035px;
                    word-spacing: 20px;
                    left: 0px;
                    top: 0px;
                  }*/
                  
                  .container:after {
                    position: absolute;
                    color: #777;
                    content: '20 40 60 80';
                    padding: 40px;
                    word-spacing: 20px;
                    left: 0px;
                    top: 0px;
                    z-index: -1;
                  }
                  .container {
                    padding: 0px;
                    position: relative;
                  }
                  
                  /* Just for demo */
                  
                  output{
                    display: block;
                    margin-top: 20px;
                    color: #777;
                  }
                  output:before{
                    content:"Selected Value: ";
                    font-weight: bold;
                  }
                  body {
                    font-family: Calibri, Arial;
                  }

                  <div class="container">
                    <input type="range" min="0" max="100" value="50" step="1" list="tickmarks" id="rangeInput" oninput="output.value = rangeInput.value">
                    <datalist id="tickmarks">
                      <option value="0 to 20">0</option>
                      <option>20</option>
                      <option>40</option>
                      <option>60</option>
                      <option>80</option>
                      <option>100</option>
                    </datalist>
                    <output id="output" for="rangeInput">50</output> <!-- Just to display selected value -->
                  </div>

                  Codepen 演示

                  这篇关于带有中间点标记的范围输入(滑块)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:两个 div 用对角线分割 - CSS 下一篇:具有 onchange 功能的 HTML5 滑块

                  相关文章

                  <tfoot id='1UXbt'></tfoot>
                  <i id='1UXbt'><tr id='1UXbt'><dt id='1UXbt'><q id='1UXbt'><span id='1UXbt'><b id='1UXbt'><form id='1UXbt'><ins id='1UXbt'></ins><ul id='1UXbt'></ul><sub id='1UXbt'></sub></form><legend id='1UXbt'></legend><bdo id='1UXbt'><pre id='1UXbt'><center id='1UXbt'></center></pre></bdo></b><th id='1UXbt'></th></span></q></dt></tr></i><div id='1UXbt'><tfoot id='1UXbt'></tfoot><dl id='1UXbt'><fieldset id='1UXbt'></fieldset></dl></div>
                • <small id='1UXbt'></small><noframes id='1UXbt'>

                    <bdo id='1UXbt'></bdo><ul id='1UXbt'></ul>

                    1. <legend id='1UXbt'><style id='1UXbt'><dir id='1UXbt'><q id='1UXbt'></q></dir></style></legend>