Firefox 标签元素边框与相对位置截断

Firefox label element border cut off with position relative

我有一些正在使用的自定义复选框。当您 select 他们时,焦点 class 就会添加到他们身上。当发生这种情况时,它周围会出现一个边框。对于大多数浏览器,边框看起来像标签元素周围的正方形。虽然在 Firefox 中左边框被切断。如果删除相对位置,则可以更正问题。尽管我不想出于定位目的这样做。我在这里创建了一个简单的示例:

http://jsfiddle.net/g617z4qk/3/

请注意,当您在 firefox 中查看时,它看起来与 chrome 有何不同。我怎样才能使 firefox 的行为像 chrome?

这里是 html 代码:

<div class="textContainter">
  <label class="input-control checkbox focus">"
     <input id="classAll" class="classAll input-control" type="checkbox" name="status" value="Item 1" tabindex="-1" checked="checked" />
     <span class="input-control-img"></span>
     <span class="input-control-text">test Item 1</span>
   </label>
</div>

这是CSS

label.input-control {
    display: inline-block;
}
.textContainter .focus {
    outline: 1px dotted !important;
 }
.input-control, .input-control .input-control-body {
   position:relative;
 }

 label.input-control input {
    left: -9999px;
    position: absolute;
 }

 label.input-control.checkbox .input-control-img {
    background-image: url("http://blogs.digitss.com/wp-      content/uploads/2010/04/fancy-radio-checkbox.png");
 }
 label.input-control .input-control-img {
   background-position: 0 0;
   background-repeat: no-repeat;
   width: 20px;
 }
 label.input-control span {
  cursor: pointer;
  float: left;
  height: 20px;
 }

这是一种解决方法。用边框替换轮廓,它在您提到的两种浏览器上都能正常工作。

这个问题似乎与 CSS "outline" different behavior behavior on Webkit & Gecko

重复

解决方法的 JSfiddle 是 border: 1px dotted;http://jsfiddle.net/g617z4qk/4/

这个输入元素定位到最左边

label.input-control input {
    left: -9999px;
    position: absolute;
 }

使标签轮廓也向左扩展(至少在 Firefox 中)。

只需为 label 元素添加 overflow:hidden 即可解决此问题:

label.input-control {
    display: inline-block;
    overflow: hidden;
}

http://jsfiddle.net/g617z4qk/5/