English 中文(简体)
我如何设置输入滑块的宽度( 像素)?
原标题:How do I set the width (in pixels) of an input slider?

此 HTML 代码 :

<div>
   <code>/range/1-3</code><br />
   <input type="range" value="0" min="0" max="100" onchange="send( /range/1 , parseInt(this.value))" /><br />
   <input type="range" value="0" min="0" max="100" onchange="send( /range/2 , parseInt(this.value))" /><br />
   <input type="range" value="0" min="0" max="100" onchange="send( /range/3 , parseInt(this.value))" />
</div>

我想在我的 HTML 文件页眉中添加一些 CSS, 以设定某些类滑动器的宽度 。

这里可以链接到整个文件, 其中包括三个 CSS 定义和一个简短的 JS, 用于将数值从滑动器中传出或传出 。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <script type="text/javascript" charset="utf-8">

      var ws = null

      window.addEventListener( load , function() {
        if ( WebSocket  in window) {
          ws = new WebSocket( ws://localhost:60001 )
          ws.onmessage = function(e) {
            var m = JSON.parse(e.data)
            if (m) {
              var e = document.getElementById(m[0])
              if (e)
                e.value = parseInt(m[1] * 100)
            }
          }
        }
      })

      function send(k, v) {
        var m = JSON.stringify([k, v])
        if (ws && ws.OPEN)
          ws.send(m)
        if (console)
          console.log(m)
      }

    </script>
        <style type="text/css" media="screen">

            div {
                margin-bottom: 1em;
            }

            code {
                color: gray;
            }
            .slider-width {
                width: 100px;
            }

    </style>
  </head>
  <body>

    <div>
      <code>/qc/lfo/1</code><br />
      <input id="/qc/lfo/1" type="range" />
    </div>

    <div>
      <code>/range/1-3</code><br />
      <input class="slider-width" type="range" value="0" min="0" max="100" onchange="send( /range/1 , parseInt(this.value))" /><br />
      <input class="slider-width" type="range" value="0" min="0" max="100" onchange="send( /range/2 , parseInt(this.value))" /><br />
      <input class="slider-width" type="range" value="0" min="0" max="100" onchange="send( /range/3 , parseInt(this.value))" />
    </div>

    <div>
      <code>/checkbox/1-3</code><br />
      <input type="checkbox" onchange="send( /checkbox/1 , this.checked)" />
      <input type="checkbox" onchange="send( /checkbox/2 , this.checked)" />
      <input type="checkbox" onchange="send( /checkbox/3 , this.checked)" />
    </div>

    <div>
      <code>/radio/1</code><br />
      <input type="radio" name="/radio/1" value="1" onchange="send( /radio/1 , 1)" />
      <input type="radio" name="/radio/1" value="2" onchange="send( /radio/1 , 2)" />
      <input type="radio" name="/radio/1" value="3" onchange="send( /radio/1 , 3)" />
    </div>

    <div>
      <code>/text/1</code><br />
      <input type="text" name="/text/1" onkeyup="send(this.name, this.value)" />
    </div>

    <div>
      <code>/select/1</code><br />
      <select name="/select/1" onchange="send(this.name, this.value)">
        <option value="First">First</option>
        <option value="Second">Second</option>
        <option value="Third">Third</option>
      </select>
    </div>

    <div>
      <code>/button/1</code><br />
      <input type="button" name="/button/1" value="button" onmousedown="send(this.name, true)" onmouseup="send(this.name, false)" onmouseout="send(this.name, false)" />
    </div>

  </body>
</html>
问题回答
.slider-width100
{
    width: 100px;
}

上面的代码是宽度定义语法, 您在给宽度打字时应该使用该语法。 这将在一个单独的 css 文件里, 它应该连接到页面中 。 要使用它, 您应该设置标签的类属性 :

class="slider-width100"

如果你的规则被其他具有更高的 cs 优先级的规则所取代, 你可以考虑在 cs 规则定义中使用这个丑陋的黑客:

.slider-width100
{
    width: 100px !important;
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签