为什么伪元素周围会有额外的space?

Why is there extra space around pseudo elements?

我在我的按钮上使用伪元素 ::after 和 ::before 来制作动画。我在 3 个不同的平台上重现了这个问题。很难看到,但角落上有额外的 space。放大后更容易看清。

我正在使用 Bootstrap,但我在使用和不使用 Bootstrap 的情况下都复制了它。

http://codepen.io/sinrise/pen/vLaGzN

<a href="#" class="btn btn-default btn-action">Test Button</button>

正常

悬停

已更新

进行了更多测试和研究,发现了真正的问题...从 a.btn-action 规则中删除 z-index: 1;

a.btn-action {
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    color: black;
    transition: color 0.4s;
    transition-delay: 0.3s;
}

Updated codepen

删除悬停伪选择器的 transform3d 过渡 class 并为 ::before 和 ::after 伪选择器添加 height: 100%;,以您想要使用的悬停动画为目标。

a.btn-action {
    position: relative;
    box-sizing: border-box;
    color: black;
    transition: color 0.4s;
    transition-delay: 0.3s;
}
a.btn-action::before, a.btn-action::after {
    position: absolute;
    top: 0;
    left: 0;
    content: "";
    width: 100%;
    height: 0;
    background: rgba(0, 0, 0, 0.1);
    -webkit-transition: all 0.2s ease 0s;
    -moz-transition: all 0.2s ease 0s;
    -ms-transition: all 0.2s ease 0s;
    -o-transition: all 0.2s ease 0s;
   transition: all 0.2s ease 0s;
   z-index: -1;
   box-sizing: border-box;
}

a.btn-action:hover::before, 
a.btn-action:hover::after {
    height:100%;
}

修改后的演示:Codepen