我想在我的网页上添加一个HTML开关,但问题是 - 我想看到切换台的MY状态,所以访问者无法更改它,但只能看到。
我有这个:
.onoffswitch {
position: relative; width: 122px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #FFFFFF; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 26px; padding: 0; line-height: 26px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "otevreno";
padding-left: 12px;
background-color: #34C258; color: #000000;
}
.onoffswitch-inner:after {
content: "zavreno";
padding-right: 12px;
background-color: #D16464; color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 5px; margin: 10.5px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 92px;
border: 2px solid #FFFFFF; border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}

<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
&#13;
我的问题是:如何让切换器对访问者无效,他们只能看到切换器的状态(&#34; otevreno&#34;或&#34; zavreno&#34;)而且只有我可以编辑切换台的状态吗?
感谢。
答案 0 :(得分:2)
将disabled
添加到您的input
代码。
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" disabled>
我修改了以下background: transparent;
和border: 2px solid transparent;
.onoffswitch-switch {
display: block;
width: 5px;
margin: 10.5px;
background: transparent;
position: absolute;
top: 0;
bottom: 0;
right: 92px;
border: 2px solid transparent;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
代码段:
.onoffswitch {
position: relative;
width: 122px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #FFFFFF;
border-radius: 20px;
}
.onoffswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before,
.onoffswitch-inner:after {
display: block;
float: left;
width: 50%;
height: 26px;
padding: 0;
line-height: 26px;
font-size: 14px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "otevreno";
padding-left: 12px;
background-color: #34C258;
color: #000000;
}
.onoffswitch-inner:after {
content: "zavreno";
padding-right: 12px;
background-color: #D16464;
color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 5px;
margin: 10.5px;
background: transparent;
position: absolute;
top: 0;
bottom: 0;
right: 92px;
border: 2px solid transparent;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" disabled>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>