我正在处理按钮相关的问题。当按钮有圆角并且内部有伪元素(before)用于模拟背景(用于过渡效果)时,我遇到了1像素的问题。伪元素before没有被正确地剪切,你可以看到在按钮边框和填充颜色之间留下了一些空隙。请查看以下示例:
你会发现,在圆角按钮上,边框和填充物之间有一个微小的线/空间。
有什么方法可以消除这个问题而保持相同的结构吗?
编辑1:我知道我可以使用background代替,但在这种情况下我不能这样做。必须通过伪元素来设置背景。
编辑2:该问题可在Win 10、Chrome和Firefox上看到。Firefox使它更加明显。最新版本:Chrome 60.0.3112.78、Firefox 54.0.1
编辑3:修改了代码以显示为什么我不能使用background属性。
你会发现,在圆角按钮上,边框和填充物之间有一个微小的线/空间。
有什么方法可以消除这个问题而保持相同的结构吗?
编辑1:我知道我可以使用background代替,但在这种情况下我不能这样做。必须通过伪元素来设置背景。
编辑2:该问题可在Win 10、Chrome和Firefox上看到。Firefox使它更加明显。最新版本:Chrome 60.0.3112.78、Firefox 54.0.1
编辑3:修改了代码以显示为什么我不能使用background属性。
a {
color: black
}
.anibtn {
display: inline-block;
overflow: hidden;
padding: 8px 20px;
margin: 0 3px 6px 3px;
text-align: center;
border: solid 10px black;
text-decoration: none;
color: $btncolor;
white-space: nowrap;
}
.anibtn-round {
display: inline-block;
overflow: hidden;
padding: 8px 20px;
margin: 0 3px 6px 3px;
text-align: center;
border: solid 10px black;
text-decoration: none;
color: $btncolor;
white-space: nowrap;
border-radius: 50px;
}
.tr-fill-on {
position: relative;
transition-duration: .3s;
}
.tr-fill-on:before {
position: absolute;
content: '';
background: black;
transition-duration: .3s;
z-index: -1;
left: 0;
top: 0;
width: 0;
height: 100%;
}
.tr-fill-on:hover {
color: white;
}
.tr-fill-on:hover:before {
width:100%;
}
.tr-fill2-on{
color: white;
position: relative;
transition-duration: .3s;
}
.tr-fill2-on:before {
position: absolute;
content: '';
background: black;
transition-duration: .3s;
z-index: -1;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.tr-fill2-on:hover {
color: black;
}
.tr-fill2-on:hover:before {
width:0;
}
<a href="#" class="anibtn tr-fill-on">Ani Buttons</a>
<a href="#" class="anibtn tr-fill2-on">Ani Buttons</a>
<a href="#" class="anibtn-round tr-fill-on">Ani Buttons</a>
<a href="#" class="anibtn-round tr-fill2-on">Ani Buttons</a>