当我尝试使用overflow: hidden;
隐藏按钮的背景效果时,我遇到了问题。我在Chrome中看到了border-radius
的一个像素:
如何隐藏这些像素?我可以尝试使用box-shadow
,但也许你知道一种更简单的方法。
<a href="#" class="btn hvr-shutter-in-horizontal">test</a>
的CSS:
.btn {
margin: 20px;
padding: 10px 30px;
font-size: 14px;
text-transform: uppercase;
color: #fff;
border: 2px solid #f0913a;
-webkit-border-radius: 20px;
border-radius: 20px;
cursor: pointer;
overflow: hidden; /* <-- I try hide background but always get http://screencast.com/t/qktgZwmVtH */
}
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
background: #181818;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: .3s;
transition-duration: .3s;
}
.hvr-shutter-in-horizontal:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #f0913a;
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transform-origin: 50%;
transform-origin: 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: .3s;
transition-duration: .3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-shutter-in-horizontal:active:before,
.hvr-shutter-in-horizontal:focus:before,
.hvr-shutter-in-horizontal:hover:before {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
答案 0 :(得分:2)
你可以使用插入阴影:
.btn {
margin: 20px;
padding: 10px 30px;
font-size: 14px;
text-transform: uppercase;
color: #fff;
border: 2px solid #f0913a;
border-radius: 20px;
cursor: pointer;
overflow:hidden;
}
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
}
.hvr-shutter-in-horizontal:before {
content: "";
position: absolute;
z-index: -1;
top: -50px;
bottom: -50px;
left: 0px;
right: 0px;
background: #f0913a;
transition: 0.5s;
border-radius: inherit;
box-shadow: inset 0 0 0 0 #181818;
}
.hvr-shutter-in-horizontal:active:before,
.hvr-shutter-in-horizontal:focus:before,
.hvr-shutter-in-horizontal:hover:before {
box-shadow: inset 0 0 0 150px #181818;
}
<a href="#" class="btn hvr-shutter-in-horizontal">test</a>
它没有根除这个虫子,但黑色不再流血了。
以避免错误,使用其他方法,您可以使用背景图像(如css渐变)并在悬停时调整其大小(也不涉及伪)。例如:
.btn {
margin: 20px;
padding: 10px 30px;
font-size: 14px;
text-transform: uppercase;
color: #fff;
border: 2px solid #f0913a;
-webkit-border-radius: 20px;
border-radius: 20px;
cursor: pointer;
overflow: hidden;
background: linear-gradient(black, black) left no-repeat, linear-gradient(black, black) right no-repeat #f0913a;
background-size: 0 100%;
transition: background-size 0.3s;
}
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
}
.hvr-shutter-in-horizontal:active,
.hvr-shutter-in-horizontal:focus,
.hvr-shutter-in-horizontal:hover {
background-size: 100% 100%;
}
<a href="#" class="btn hvr-shutter-in-horizontal">test</a>
答案 1 :(得分:2)
您只需在课程background-clip:padding-box;
.hvr-shutter-in-horizontal
即可
<强> CSS:强>
.btn {
margin: 20px;
padding: 10px 30px;
font-size: 14px;
text-transform: uppercase;
color: #fff;
border: 2px solid #f0913a;
-webkit-border-radius: 20px;
border-radius: 20px;
cursor: pointer;
overflow: hidden;
}
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
background: #181818;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: .3s;
transition-duration: .3s;
/* Prevent background color leak outs */
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
.hvr-shutter-in-horizontal:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #f0913a;
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transform-origin: 50%;
transform-origin: 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: .3s;
transition-duration: .3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-shutter-in-horizontal:active:before,
.hvr-shutter-in-horizontal:focus:before,
.hvr-shutter-in-horizontal:hover:before {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
演示jsfiddle:https://jsfiddle.net/hamzanisar/wd9exfmx/9/
答案 2 :(得分:0)
删除溢出:隐藏在.btn类中并更改:before元素的左右属性,同时将border-radius设置为继承:before元素检查此处的小提琴,例如https://jsfiddle.net/0ap4qbrn/
.btn {
margin: 20px;
padding: 10px 30px;
font-size: 14px;
text-transform: uppercase;
color: #fff;
border: 2px solid #f0913a;
-webkit-border-radius: 20px;
border-radius: 20px;
cursor: pointer;
}
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
background: #181818;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: .3s;
transition-duration: .3s;
}
.hvr-shutter-in-horizontal:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: -2px;/*equal to the border width of .btn but negated*/
right: -2px;/*equal to the border width of .btn but negated*/
background: #f0913a;
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transform-origin: 50%;
transform-origin: 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: .3s;
transition-duration: .3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
border-radius: inherit;
}
.hvr-shutter-in-horizontal:active:before,
.hvr-shutter-in-horizontal:focus:before,
.hvr-shutter-in-horizontal:hover:before {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
答案 3 :(得分:-3)
给盒子大小:边框;使用webkit和moz前缀可以解决您的问题