html - 复选框和单选按钮样式在 Firefox 中不起作用

标签 html css

我知道这是一个老问题,已经回答了很多次,但我不知道如何从其他示例中合并一个修复基础。

确定复选框样式后,它在 Chrome 和 Opera 中看起来不错(它应该看起来如何),但在 Firefox 和 IE 中它看起来仍然像丑陋的复选框。有没有一种简单的方法可以解决此问题,使其在所有浏览器中看起来都一样?如果可以的话,请对我的 CSS 有新看法的人帮我解决这个问题。我使用的是联系表格 7,因此 HTML 不可更改,否则我会根据其他教程自行更改 HTML 代码和样式。

/*Below is for Radio Buttons*/
.wpcf7-form-control.wpcf7-radio input[type="radio" ] {
    margin: 5px 20px 0px 3px;
    border: 2px solid #35a4d5;
    padding: 10px;
    -webkit-appearance: none;
    border-radius: 50%;
}
.wpcf7-list-item.first .wpcf7-list-item-label,.wpcf7-list-item.last .wpcf7-list-item-label {
    font-size: 18px;
    vertical-align: 5px;
}
.wpcf7-form-control.wpcf7-radio input[type="radio" ]:checked{
  background:#555;
  box-shadow: inset 0px 0px 0px 3px white;
  -webkit-box-shadow: inset 0px 0px 0px 3px white;
  -moz-box-shadow: inset 0px 0px 0px 3px white;
  -o-box-shadow: inset 0px 0px 0px 3px white;
  -webkit-border-radius: 100%;
  -moz-border-radius: 100%;
  -o-border-radius: 100%;
}
.wpcf7-form-control.wpcf7-radio input:focus{
  outline:none;
}
/*END*/



/*Below is for Check Boxes*/
.wpcf7-form-control.wpcf7-checkbox input[type="checkbox" ]{
  margin: 5px 4px 0px 3px;
    border: 2px solid #35a4d5;
    padding: 10px;
    -webkit-appearance: none;
}
.wpcf7-list-item.first.last .wpcf7-list-item-label{
  font-size: 20px;
  vertical-align: 5px;
}
.wpcf7-form-control.wpcf7-checkbox input[type="checkbox" ]:checked{
  background:#555;
  box-shadow: inset 0px 0px 0px 3px white;
  -webkit-box-shadow: inset 0px 0px 0px 3px white;
  -moz-box-shadow: inset 0px 0px 0px 3px white;
  -o-box-shadow: inset 0px 0px 0px 3px white;
}
.wpcf7-form-control.wpcf7-checkbox input:focus{
  outline:none;
}
/*END*/
<span class="wpcf7-form-control-wrap RVCategory">
     <span class="wpcf7-form-control wpcf7-radio">
          <span class="wpcf7-list-item first">
               <span class="wpcf7-list-item-label" style="">Motorhome
               </span> &nbsp;
<input type="radio" name="RVCategory" value="Motorhome" checked="checked">
</span>
<span class="wpcf7-list-item last">
          <span class="wpcf7-list-item-label">Trailer
          </span>&nbsp;
<input type="radio" name="RVCategory" value="Trailer">
</span>
</span>
</span>
<p></p>
<span class="myCheckboxes">
     <span class="wpcf7-form-control-wrap checkbox-112">
          <span class="wpcf7-form-control wpcf7-checkbox">
               <span class="wpcf7-list-item first last">
                    <input type="checkbox" name="checkbox-112[]" value="Electric Generator"> 
                    <span class="wpcf7-list-item-label">Electric Generator</span>
               </span>
          </span>
     </span>
</span>

最佳答案

我最近做了一个元素,需要自定义复选框和单选样式,并要求与跨浏览器兼容。不幸的是,仅通过样式化 input 标签,您无法在 Firefox 和大多数 IE 中实现它。如果您愿意稍微重构一下 HTML,这就是我使用的方法。

我很快就把它拼凑在一起,所以我可能遗漏了一些我在生产中使用的东西。它非常简单,HTML 只需要输入和输入后的标签。

<input type="checkbox" id="checkbox1" name="checkbox">
<label for="checkbox1">Checkbox One</label>

现在 CSS 看起来像:

/* Hide inputs visually from being seen - don't use display: none as this will break in accessibility */
input[type="checkbox"],
input[type="radio"] {
  float: left;
  opacity: 0.01;
  position: absolute;
}

input[type="checkbox"] + label,
input[type="radio"] + label {
  display: inline-block;
  line-height: 1.4;
  margin: 0;
  padding-left: 30px;
  position: relative;
}

/* Actually create a fake input element with pseudo */
input[type="checkbox"] + label::before,
input[type="radio"] + label::before {
  background: no-repeat center center;
  border: 1px solid #a6a6a6;
  border-radius: 3px;
  content: "";
  cursor: pointer;
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  top: -1px;
  width: 20px;
}

/* Fake Styling for checked state */
input[type="checkbox"]:checked + label::before,
input[type="radio"]:checked + label::before {
  background-color: #00ba00;
  background-image: url(something);
  background-size: 10px 8px;
  border-color: #00ba00;
}

/* Because this element isn't actually an input I've added the accessibility focus rings */
input[type="checkbox"]:focus + label::before,
input[type="radio"]:focus + label::before {
  outline: auto 5px -webkit-focus-ring-color;
}

/* Radio button styling */
input[type="radio"] + label::before {
  border-radius: 50%;
}

input[type="radio"]:checked + label::before {
  background-color: #00ba00;
  background-image: url(something);
  background-position: center center;
  background-repeat: no-repeat;
  background-size: 8px 8px;
}

这是它的实际代码笔 http://codepen.io/jerrylow/pen/BzPkZw

关于html - 复选框和单选按钮样式在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38668420/

相关文章:

html - 带有 onclick 链接的嵌入式 youtube 播放器在同一嵌入式播放器中播放另一个视频

java - JSP 看不到资源文件夹中的 CSS 和 JS 文件

HTML/CSS 从使用 CSS 加载到 SPAN 中的图像中删除边框(或轮廓)

html - 如何调整图像大小以适应浏览器窗口?

javascript - 如何将元素放置在轴上(以完美贴合)?

css - 极其基本的 HTML 格式

html - 如何居中对齐 float : left ul/li navigation menu with css?

javascript - Bootstrap 移动下拉菜单

php - 从 mysql 迁移到新服务器时出现斜杠?

html - 如何将标题放在导航栏的中间?