css - 在移动设备上查看时缺少自定义 CSS 复选框边距

标签 css checkbox

我有一个用 CSS 编写的自定义复选框,在开发中看起来符合预期。但是当它在移动设备上(通过 Heroku)查看时,右边距不会显示,如下所示:

enter image description here

知道为什么在 CSS 中正确设置右边距后它会消失吗?

自定义复选框 CSS:

input[type="checkbox"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
  position: relative;
  border: none;
  margin-bottom: -4px;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
input[type="checkbox"]:focus,
.checkbox input[type="checkbox"]:focus,
.checkbox-inline input[type="checkbox"]:focus {
  outline: none;
}
input[type="checkbox"]:after,
.checkbox input[type="checkbox"]:after,
.checkbox-inline input[type="checkbox"]:after {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin-top: -2px;
  margin-right: 1rem;
  border: 2px solid #8D8D8D;
  border-radius: 4px;
  -webkit-transition: 240ms;
  -o-transition: 240ms;
  transition: 240ms;
}
input[type="checkbox"]:checked:before,
.checkbox input[type="checkbox"]:checked:before,
.checkbox-inline input[type="checkbox"]:checked:before {
  content: "";
  position: absolute;
  top: 0;
  left: 6px;
  display: table;
  width: 6px;
  height: 12px;
  border: 2px solid #fff;
  border-top-width: 0;
  border-left-width: 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  transform: rotate(45deg);
}
input[type="checkbox"]:checked:after,
.checkbox input[type="checkbox"]:checked:after,
.checkbox-inline input[type="checkbox"]:checked:after {
  background-color: #00B1FF;
  border-color: #00B1FF;
}
input[type="checkbox"]:disabled:after,
.checkbox input[type="checkbox"]:disabled:after,
.checkbox-inline input[type="checkbox"]:disabled:after {
  border-color: #DFDFDF;
}
input[type="checkbox"]:disabled:checked:after,
.checkbox input[type="checkbox"]:disabled:checked:after,
.checkbox-inline input[type="checkbox"]:disabled:checked:after {
  background-color: #DFDFDF;
  border-color: transparent;
}
.has-warning input:not([type=checkbox]),
.has-warning .form-control,
.has-warning input.form-control[readonly],
.has-warning input[type=text][readonly],
.has-warning [type=text].form-control[readonly],
.has-warning input:not([type=checkbox]):focus,
.has-warning .form-control:focus {
  border-bottom: none;
  -webkit-box-shadow: inset 0 -2px 0 #FFD200;
  box-shadow: inset 0 -2px 0 #FFD200;
}
.has-error input:not([type=checkbox]),
.has-error .form-control,
.has-error input.form-control[readonly],
.has-error input[type=text][readonly],
.has-error [type=text].form-control[readonly],
.has-error input:not([type=checkbox]):focus,
.has-error .form-control:focus {
  border-bottom: none;
  -webkit-box-shadow: inset 0 -2px 0 #FF193C;
  box-shadow: inset 0 -2px 0 #FF193C;
}
.has-success input:not([type=checkbox]),
.has-success .form-control,
.has-success input.form-control[readonly],
.has-success input[type=text][readonly],
.has-success [type=text].form-control[readonly],
.has-success input:not([type=checkbox]):focus,
.has-success .form-control:focus {
  border-bottom: none;
  -webkit-box-shadow: inset 0 -2px 0 #00FFD2;
  box-shadow: inset 0 -2px 0 #00FFD2;
}
.has-warning .input-group-addon,
.has-error .input-group-addon,
.has-success .input-group-addon {
  color: #F8F8F8;
  border-color: transparent;
  background-color: transparent;
}

最佳答案

我的 friend 提供了答案。关键是移动线:

margin-right: 1rem;

到第一个 block :

input[type="checkbox"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
  position: relative;
  border: none;
  margin-bottom: -4px;
  margin-right: 1rem;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

我还将 display: table 更改为 display: block

现在一切看起来都如愿。

关于css - 在移动设备上查看时缺少自定义 CSS 复选框边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32828709/

相关文章:

CSS 规则被覆盖

html - 使用 CSS 问题的样式

javascript - 如何按顺序应用 CSS 更改?

jquery - 如何将多个复选框值传递到数组中

jquery - 复选框 css/jquery 样式更改

android - 强制动态生成的复选框只允许选择一个

css - 根据柔性显示中的百分比宽度自动设置高度

css - 底部的导航栏隐藏了表格——如何在 bootstrap 3/custom css 中修复?

用于设置自定义字体的 Android 自定义复选框

javascript - 取消选中嵌套复选框后禁用提交按钮