3

我想在“垂直”中显示范围输入滑块。

我使用此代码显示垂直-webkit-appearance: slider-vertical它显示滑块但 css 不工作它显示普通输入范围滑块。

谁能帮我怎么做。

这是我的代码

<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;"/>
    <title>How to style an HTML5 range input with CSS</title>
    <style type="text/css" media="screen">
        body {
            font-family: Helvetica, sans-serif;
            margin: 0;
            padding: 10px;
        }
        input[type='range'] {
            -webkit-appearance: slider-vertical !important;
            -webkit-border-radius: 10px;
            -webkit-box-shadow: inset 0 0 5px #333;
            background-color: #157DEC;
            display: block;
            height: 15px;
            left: 10px;
            margin: -100px 0 0 100px;
            position: absolute;
            right: 10px;
        }
        input[type='range']::-webkit-slider-thumb {
            -webkit-appearance:  none !important;
            -webkit-border-radius: 10px;
            background-color: #FFFFFF;
            background-image: -webkit-gradient(circular, left top, left bottom, from(##FFFFFF), to(#AAA));
            border: 1px solid #999;
            height: 33px;
            width: 33px;
        }
        #range {
            display: block;
            font-size: 200%;
            font-weight: bold;
            margin: -58px -12px 107px 4px ;
            text-align: center;
        }
        p {
            position: absolute;
            bottom: 0;
            left: 10px;
            font-size: 10px;
            right: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="wrapper">
        <span id="range">0</span>
        <input type=range name=salary min="0" max="5" value="0" step="1" onchange="showValue(this.value)" />


    </div>
    <script type="text/javascript">
        function showValue(newValue) {
            document.getElementById("range").innerHTML=newValue;
        }
    </script>
</body>
</html>
4

1 回答 1

1

不要在你的CSS中身高。你强迫到一个固定的尺寸。

这是我对你的风格的建议

   body {
        font-family: Helvetica, sans-serif;
        margin: 0;
        padding: 10px;
        overflow:hidden;
    }
    input[type='range'] {
        -webkit-appearance: slider-vertical;/*comment this to see the result*/
        -webkit-border-radius: 10px;
        -webkit-box-shadow: inset 0 0 5px #333;
        background-color: #157DEC;
        display: block;
        /*height: 15px;*/
        left: 10px;
        /*margin: -100px 0 0 100px;*/
        /*position: absolute;*/
        right: 10px;
        margin-top:50px;
    }
    input[type='range']::-webkit-slider-thumb {
        -webkit-appearance:  none !important;
        -webkit-border-radius: 10px;
        background-color: #FFFFFF;
        background-image: -webkit-gradient(circular, left top, left bottom, from(##FFFFFF), to(#AAA));
        border: 1px solid #999;
       /* height: 33px;*/
        width: 33px;
    }
    #range {
        display: block;
        font-size: 200%;
        font-weight: bold;
        margin: -58px -12px 107px 4px ;
        text-align: center;
    }
    p {
        position: absolute;
        bottom: 0;
        left: 10px;
        font-size: 10px;
        right: 10px;
        text-align: center;
    }

这里是小提琴的预览:http: //jsfiddle.net/QXzLT/

于 2013-05-31T10:09:07.017 回答