cross browser custom checkbox

寵の児 提交于 2020-01-23 03:10:48

问题


I have HTML and CSS code that I've used to build a custom checkbox. I believe my code has the correct web-kits but it doesn't seem to work on FireFox.

Here's the code:

HTML

 <input type='checkbox' style="float: left" class='regular-checkbox big-checkbox'
     checked='checked' id='product-45-45' name='product_id_page-0[45-45]'
     value='45-45' data-first_price="11.99" data-second_price="" data-paysys="" />

CSS

.regular-checkbox {
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #fafafa;
    border: 1px solid #cacece;
    box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 -15px 10px -12px rgba(0,0,0,0);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 -15px 10px -12px rgba(0,0,0,0);
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 -15px 10px -12px rgba(0,0,0,0);
    padding: 9px;
    border-radius: 20px;
    -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    display: inline-block;
    position: relative;
}
.regular-checkbox:active,
.regular-checkbox:checked:active {
    box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 1px 3px rgba(0,0,0,0);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 1px 3px rgba(0,0,0,0);
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 1px 3px rgba(0,0,0,0);
}
.regular-checkbox:checked {
    background-color: #e9ecee;
    box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 -15px 10px -12px rgba(0,0,0,0),inset 15px 10px -12px rgba(255,0,0,0);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 -15px 10px -12px rgba(0,0,0,0),inset 15px 10px -12px rgba(255,0,0,0);
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0),inset 0 -15px 10px -12px rgba(0,0,0,0),inset 15px 10px -12px rgba(255,0,0,0);
}
.regular-checkbox:checked:after {
    content: '\2714';
    font-size: 14px;
    position: absolute;
    top: 0;
    left: 3px;
    color: #19a73e;
}
.big-checkbox {
    padding: 18px;
}
.big-checkbox:checked:after {
    font-size: 37px;
    top: -7px;
    left: 2px;
}

Screen shot of the desired outcome (works in Chrome):


回答1:


Try use this code, I don't know explain, but I did one version for you ;)

.regular-checkbox{
		display: inline-block;
		border-radius: 50%;
		width: 38px;
		height: 38px;
		border: 1px solid #ccc;
	}
	.regular-checkbox input{
		opacity: 0;
		position: absolute;
	}
	.regular-checkbox small{
		width: 100%;
		height: 100%;
		float: left;
	}
	.regular-checkbox input:checked ~ small:after{
		content: '\2714';
		height: 38px; 
		width: 38px;
		color: green;
		font-size: 26px;
		text-align: center;
		float: left;
	}
<label class="regular-checkbox">
    <input type="checkbox">
    <small></small>
</label>



回答2:


This is a known issue in Firefox - there's a workaround with using <label> and <span>.

MDN also mentions that styling some form elements is a bit of a pain - read more here.

.checkbox input[type="checkbox"] {
  display: none;
}
.checkbox span {
  background-color: #fafafa;
  border: 1px solid #cacece;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0), inset 0 -15px 10px -12px rgba(0, 0, 0, 0);
  padding: 22px;
  -webkit-border-radius: 50%;
  border-radius: 50%;
  display: inline-block;
  position: relative;
}
.checkbox :active + span,
.checkbox :checked:active span {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0), inset 0 1px 3px rgba(0, 0, 0, 0);
}
.checkbox :checked + span {
  background-color: #e9ecee;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0), inset 0 -15px 10px -12px rgba(0, 0, 0, 0), inset 15px 10px -12px rgba(255, 0, 0, 0);
}
.checkbox :checked + span:after {
  content: '\2714';
  font-size: 14px;
  position: absolute;
  top: 0;
  left: 0px;
  width: 100%;
  color: #19a73e;
  text-align: center;
}
.big-checkbox {
  padding: 18px;
}
.big-checkbox:checked + span:after {
  font-size: 37px;
}
<label class="checkbox" for="product-45-45">
  <input type='checkbox' style="float: left" class='regular-checkbox big-checkbox' checked='checked' id='product-45-45' name='product_id_page-0[45-45]' value='45-45' data-first_price="11.99" data-second_price="" data-paysys="" />
  <span></span>
</label>


来源:https://stackoverflow.com/questions/39732253/cross-browser-custom-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!