复选框内容IE 11 / Edge

时间:2016-06-28 18:37:25

标签: html5 css3 checkbox internet-explorer-11 microsoft-edge

我在IE和Edge中遇到checkbox的问题,即“内容”类。我有以下代码:

<input id="checkbox" type="checkbox" class="checkbox-edit-article" name="breakingNews" ng-model="showPublished" ng-change="updateCategory(selectedCategory, pageID)">
    <label for="checkbox" class="checkbox-edit-article-label">
        Show only published articles
    </label>
</input>

检查字段时

.checkbox-edit-article:checked + .checkbox-edit-article-label:before {
    content: url(../img/mark-white.png);
    background: rgb(49,119,61);
    color: #fff;
    height: 44px;
    line-height: 2.4;
    transition: all .2s;
}

和静态

.checkbox-edit-article + .checkbox-edit-article-label:before {
    content: '';
    background: #fff;
    border: 1px solid #BFBFBF;
    display: inline-block;
    vertical-align: middle;
    width: 43px;
    height: 44px;
    margin-right: 10px;
    margin-top: 1px;
    text-align: center;
    box-shadow: inset 0px 0px 0px 1px white;
}

在Chrome中content: url(../img/mark-white.png);显示效果很好,但在IE中,由于line-height,此检查图片太高,但我不知道如何将图片置于复选框中心。

我问你的帮助,我如何调整图像?

提前谢谢!

1 个答案:

答案 0 :(得分:1)

您将图片放在background中,而不是像这样

background: rgb(49,119,61) url(../img/mark-white.png) no-repeat center center;

示例代码段

.checkbox-edit-article:checked + .checkbox-edit-article-label:before {
  content: '';
  background: rgb(49,119,61) url(http://i.stack.imgur.com/NOQI7.png) no-repeat center center;
  background-size: 25px 25px;  /* this I just added to make my bigger mark be small */
  color: #fff;
  height: 44px;
  transition: all .2s;
}
.checkbox-edit-article + .checkbox-edit-article-label:before {
  content: '';
  background: #fff;
  border: 1px solid #BFBFBF;
  display: inline-block;
  vertical-align: middle;
  width: 43px;
  height: 44px;
  margin-right: 10px;
  margin-top: 1px;
  text-align: center;
  box-shadow: inset 0px 0px 0px 1px white;
}
<input id="checkbox" type="checkbox" class="checkbox-edit-article" name="breakingNews" ng-model="showPublished" ng-change="updateCategory(selectedCategory, pageID)">
<label for="checkbox" class="checkbox-edit-article-label">Show only published articles</label>