【问题标题】:Styling input range lower in CSS for Webkit?Webkit的CSS样式输入范围较低?
【发布时间】:2017-03-23 12:01:46
【问题描述】:

我正在使用 CSS 设计 input[type=range],并使用 thumbtrack 完成。
所有三个(-ms-moz-webkit)浏览器都有正确的前缀。

但是,我不知道什么供应商前缀适合在 Webkit 浏览器(例如 Chrome)上设置 progress 样式。 在 Internet Explorer 和 Microsoft Edge 上,-ms-fill-lower 效果很好。
在 Firefox 上,使用 -moz-range-progress 解决了这个问题。

input[type=range] {
	/*removes default webkit styles*/
	-webkit-appearance: none;
	
	/*fix for FF unable to apply focus style bug */
	border: 1px solid white;
	
	/*required for proper track sizing in FF*/
	width: 350px;
}

/* Webkit, Chrome & Safari */
input[type=range]::-webkit-slider-runnable-track { 
	width: 300px;
	height: 5px;
	background: #ccc;
	border: none;
	border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
	-webkit-appearance: none;
	border: none;
	height: 16px;
	width: 16px;
	border-radius: 50%;
	background: #004d66;
	margin-top: -7px;
}
input[type=range]:focus {
	outline: none;
}
input[type=range]:focus::-webkit-slider-runnable-track {
	background: #ddd;
}
/* moz://a Firefox */
input[type=range]::-moz-range-track {
	/* width: 150px;
	height: 5px; */
	background: #ccc;
	border: none;
	border-radius: 3px;
}
input[type=range]::-moz-range-thumb {
	border: none;
	height: 16px;
	width: 16px;
	border-radius: 50%;
	background: #004d66;
}
input[type=range]::-moz-range-progress {
	background: #33ccff;
	border-radius: 10px;
	height: 5px;
}

/*hide the outline behind the border*/
input[type=range]:-moz-focusring{
	outline: 1px solid white;
	outline-offset: -1px;
}


/* Microsoft */
input[type=range]::-ms-track {
	
	height: 2px;
	/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
	background: transparent;
	
	/*leave room for the larger thumb to overflow with a transparent border */
	border-color: transparent;
	border-width: 6px 0;

	/*remove default tick marks*/
	color: transparent;
}
input[type=range]::-ms-thumb {
	border: none;
	height: 16px;
	width: 16px;
	border-radius: 50%;
	background: #004d66;
	margin-top: 1px;
}
input[type=range]::-ms-fill-lower {
	background: #33ccff;
	border-radius: 10px;
	height: 5px;
}
input[type=range]::-ms-fill-upper {
	background: #ccc;
	border-radius: 10px;
}
input[type=range]:focus::-ms-fill-lower {
	background: #44ddff;
}
input[type=range]:focus::-ms-fill-upper {
	background: #ddd;
}
<input type="range" />
此示例在 Microsoft Edge、moz://a Firefox 和 Internet Explorer 上可以正常工作,但在 Chrome 上看起来不同。

我已经阅读了Styling input range for webkit with pure CSS,并尝试过我的,
但是当多个输入[type=range]在一个文档上时,它会奇怪地工作。

所以,问题是,
是否有任何适当的供应商前缀用于设置拇指已经通过的样式轨道,仅使用 CSS?

【问题讨论】:

标签: css webkit


【解决方案1】:

据我所知,这是不可能的。下面是来自 Chrome 的 sn-p,显示了 <input type="range" /> 的 Shadow DOM 元素:

<input type="range">
    #shadow-root (user-agent)
        <div style="-webkit-appearance:inherit">
            <div pseudo="-webkit-slider-runnable-track" id="track">
               <div id="thumb">
               </div>
        </div>
    </div>
</input>

一般来说,您可能想看看range.css,它是一个用于自定义范围滑块的跨浏览器代码生成器。但是,它不提供设置::-moz-range-progress 区域样式的方法。我发现的其他示例,包括这个Codepen sn-p,使用已弃用且不再起作用的deep shadow-piercing 选择器。对于完全跨浏览器的解决方案,您必须制作自己的元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多