首先,设置高度大于宽度。在理论上,这是你应该需要的。
HTML5 Spec suggests as much:
… the UA determined the orientation of the control from the ratio of the style-sheet-specified height and width properties.
Opera已经实现了这种方式,但Opera现在使用WebKit Blink.到今天为止,没有浏览器实现一个垂直滑块只基于高度大于宽度。
无论如何,设置高度大于宽度需要在浏览器之间获得正确的布局。应用左右填充也有助于布局和定位。
对于Chrome,请使用-webkit-appearance:slider-vertical。
对于IE,使用writing-mode:bt-lr。
对于Firefox,向html中添加一个orient =“vertical”属性。可惜他们这样做了。视觉样式应该通过CSS控制,而不是HTML。
input[type=range][orient=vertical]
{
writing-mode: bt-lr; /* IE */
-webkit-appearance: slider-vertical; /* WebKit */
width: 8px;
height: 175px;
padding: 0 5px;
}
免责声明:
此解决方案基于当前浏览器实现的尚未定义或未定义的CSS属性。如果您打算在代码中使用它,请准备好在更新的浏览器版本发布和w3c建议完成时进行代码调整。