输入范围样式IE11 / Firefox与Chrome相同

时间:2019-09-10 18:53:16

标签: css google-chrome internet-explorer firefox cross-browser

我在Chrome中设置了范围滑块的样式。.我遇到了一些主要问题,试图使它在IE11和firefox中看起来相同。和moz-用于webkit标签,但格式仍然不一样。我了解这可能有所不同,但结果相差无几。这是到目前为止的代码。基本上,范围滑块的格式应与其上方的按钮相同。

Page not found (404)
Request Method: GET
Request URL:    http://192.168.0.114:8686/test
Using the URLconf defined in couponer.urls, Django tried these URL patterns, in this order:

^ ^$ [name='api-root']
^ ^\.(?P<format>[a-z0-9]+)/?$ [name='api-root']
admin/
^ ^^p//$ [name='udemylinks-list']
^ ^^p\.(?P<format>[a-z0-9]+)/?$ [name='udemylinks-list']
^ ^^p//(?P<pk>[^/.]+)/$ [name='udemylinks-detail']
^ ^^p//(?P<pk>[^/.]+)\.(?P<format>[a-z0-9]+)/?$ [name='udemylinks-detail']
^ ^$ [name='api-root']
^ ^\.(?P<format>[a-z0-9]+)/?$ [name='api-root']
^pages/(?P<page_no>\d+)/$ [name='Pages']
^html/(?P<page_no>\d+)/$ [name='index']
^test/(?P<page_no>\d+)/$ [name='test_page']
The current path, test, didn't match any of these.
.switch {
	position: relative;
	display: block;
	vertical-align: top;
	width: 100px;
	height: 30px;
	padding: 3px;
	margin: 0 10px 10px 0;
	background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
	background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
	border-radius: 18px;
	box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
	cursor: pointer;
	box-sizing:content-box;
}
.switch-input {
	position: absolute;
	top: 0;
	left: 0;
	opacity: 0;
	box-sizing:content-box;
}
.switch-label {
	position: relative;
	display: block;
	height: inherit;
	font-size: 10px;
	text-transform: uppercase;
	background: #eceeef;
	border-radius: inherit;
	box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
	box-sizing:content-box;
}
.switch-label_1 {
	position: relative;
	display: block;
	height: inherit;
	font-size: 10px;
	text-transform: uppercase;
	background: #eceeef;
	border-radius: inherit;
	box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
	box-sizing:content-box;
}
.switch-label:before, .switch-label:after, .switch-label_1:before, .switch-label_1:after {
	position: absolute;
	top: 50%;
	margin-top: -.5em;
	line-height: 1;
	-webkit-transition: inherit;
	-moz-transition: inherit;
	-o-transition: inherit;
	transition: inherit;
	box-sizing:content-box;
}
.switch-label:before, .switch-label_1:before {
	content: attr(data-off);
	right: 11px;
	color: #aaaaaa;
	text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after, .switch-label_1:after {
	content: attr(data-on);
	left: 11px;
	color: #FFFFFF;
	text-shadow: 0 1px rgba(0, 0, 0, 0.2);
	opacity: 0;
}
.switch-input:checked ~ .switch-label {
	background: #86b692;
	box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
	opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
	opacity: 1;
}

.switch-input:checked ~ .switch-label_1 {
	background: #a9d2d5;
	box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label_1:before {
	opacity: 0;
}
.switch-input:checked ~ .switch-label_1:after {
	opacity: 1;
}

.switch-handle {
	position: absolute;
	top: 4px;
	left: 4px;
	width: 28px;
	height: 28px;
	background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
	background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
	border-radius: 100%;
	box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	margin: -6px 0 0 -6px;
	width: 12px;
	height: 12px;
	background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
	background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
	border-radius: 6px;
	box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
	left: 74px;
	box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
 
/* Transition
========================== */
.switch-label, .switch-label_1, .switch-handle {
	transition: All 0.3s ease;
	-webkit-transition: All 0.3s ease;
	-moz-transition: All 0.3s ease;
	-o-transition: All 0.3s ease;
}

.range {
  	display: block;
	vertical-align: top;
	width: 300px;
	height: 30px;
	padding: 3px;
	margin: 0 10px 10px 0;
	background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
	background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
	border-radius: 18px;
	box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
	cursor: pointer;
	box-sizing:content-box;
}

.range-frame{
	position: relative;
	display: block;
	height: inherit;
	font-size: 10px;
	background: #eceeef;
	border-radius: inherit;
	box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
	box-sizing:content-box;
}



input[type=range] {
  -webkit-appearance: none;
    margin: 10px 0;
  width: 100%;
}
input[type=range]:focus {
  outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 35px;
  cursor: pointer;
  animate: 0.2s;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  background: lightgray;
  border-radius: 25px;
  border: 0px solid #000101;
}
input[type=range]::-webkit-slider-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 35px;
  width: 39px;
  border-radius: 35px;
  background: silver;
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -1px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
  background: lightgray;
}
input[type=range]::-moz-range-track {
  width: 100%;
  height: 35px;
  cursor: pointer;
  animate: 0.2s;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  background: lightgray;
  border-radius: 25px;
  border: 0px solid #000101;
}
input[type=range]::-moz-range-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 35px;
  width: 39px;
  border-radius: 35px;
  background: silver;
  cursor: pointer;
}
input[type=range]::-ms-track {
  width: 100%;
  height: 35px;
  cursor: pointer;
  animate: 0.2s;
  background: transparent;
  border-color: transparent;
  border-width: 39px 0;
  color: transparent;
}
input[type=range]::-ms-fill-lower {
  background: lightgray;
  border: 0px solid #000101;
  border-radius: 35px;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
}
input[type=range]::-ms-fill-upper {
  background: transparent;
  border: 0px solid #000101;
   border-radius: 35px;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
}
input[type=range]::-ms-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 35px;
  width: 39px;
  border-radius: 35px;
  background: silver;
  cursor: pointer;
}
input[type=range]:focus::-ms-fill-lower {
  background: lightgray;
}
input[type=range]:focus::-ms-fill-upper {
  background:lightgray;
}


.output-value{
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  color: #aaaaaa;
  pointer-events: none;
  
}

这是所有浏览器上的外观-

谢谢 C

1 个答案:

答案 0 :(得分:1)

输入类型范围可完全自定义。不幸的是,每个浏览器都有自己的方式,因此我们必须编写比预期更长的代码。而且,您也不会获得完全类似的结果。结果看起来与其他浏览器没有什么不同。

您可以在下面参考一个示例,我尝试对其进行自定义以使其看起来像您的范围滑块。我在各种浏览器上进行了测试,并且在大多数浏览器中看起来都差不多。

<!DOCTYPE html>
<html>
<head>
<style>
input[type=range] {
  -webkit-appearance: none;
  margin: 10px 0;
  width: 100%;
}
input[type=range]:focus {
  outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 35px;
  cursor: pointer;
  animate: 0.2s;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  background: lightgray;
  border-radius: 25px;
  border: 0px solid #000101;
}
input[type=range]::-webkit-slider-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 35px;
  width: 39px;
  border-radius: 35px;
  background: silver;
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -1px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
  background: lightgray;
}
input[type=range]::-moz-range-track {
  width: 100%;
  height: 35px;
  cursor: pointer;
  animate: 0.2s;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  background: lightgray;
  border-radius: 25px;
  border: 0px solid #000101;
}
input[type=range]::-moz-range-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 35px;
  width: 39px;
  border-radius: 35px;
  background: silver;
  cursor: pointer;
}
input[type=range]::-ms-track {
  width: 100%;
  height: 35px;
  cursor: pointer;
  animate: 0.2s;
  background: transparent;
  border-color: transparent;
  border-width: 39px 0;
  color: transparent;
}
input[type=range]::-ms-fill-lower {
  background: lightgray;
  border: 0px solid #000101;
  border-radius: 35px;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
}
input[type=range]::-ms-fill-upper {
  background: lightgray;
  border: 0px solid #000101;
   border-radius: 35px;
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
}
input[type=range]::-ms-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 35px;
  width: 39px;
  border-radius: 35px;
  background: silver;
  cursor: pointer;
}
input[type=range]:focus::-ms-fill-lower {
  background: lightgray;
}
input[type=range]:focus::-ms-fill-upper {
  background:lightgray;
}

body {
  padding: 30px;
}

</style>
</head>
<body>

<input type="range">


</body>
</html>

在各种浏览器中的输出:

enter image description here

参考:

(1)Codepen example

(2)Styling Cross-Browser Compatible Range Inputs with CSS

此外,您可以尝试根据自己的要求对其进行修改,或者将其用作在您自己的代码中进行更改的参考。

相关问题