在悬停时填充元素与倾斜的背景

时间:2015-11-23 11:00:15

标签: css css3 hover css-transitions css-shapes

我正在尝试创建 CSS按钮悬停效果。但我没有设法以倾斜的形状填充元素。

如何计划悬停效果:

Fill button with slanted shape on hover

屏幕截图1:它实际上看起来如何。

屏幕截图2:我希望悬停效果看起来像是倾斜的一面。



.button_sliding_bg {
  color: #31302B;
  background: #FFF;
  padding: 12px 17px;
  margin: 25px;
  font-family: 'OpenSansBold', sans-serif;
  border: 3px solid #31302B;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 2px;
  display: inline-block;
  text-align: center;
  cursor: pointer;
  box-shadow: inset 0 0 0 0 #31302B;
  -webkit-transition: all ease 0.8s;
  -moz-transition: all ease 0.8s;
  transition: all ease 0.8s;
}
.button_sliding_bg:hover {
  box-shadow: inset 200px 0 0 0 #31302B;
  color: #FFF;
}

<button class="button_sliding_bg">Buttontext</button>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

您可以使用css :after

Jsfiddle

.button_sliding_bg {
    color: #31302B;
    background: #FFF;
    padding: 12px 17px;
    margin: 25px;
    font-family:'OpenSansBold', sans-serif;
    border: 3px solid #31302B;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-radius: 2px;
    display: inline-block;
    text-align: center;
    cursor: pointer;
    box-shadow: inset 0 0 0 0 #31302B;
    -webkit-transition: all ease 0.8s;
    -moz-transition: all ease 0.8s;
    transition: all ease 0.8s;
    position: relative;
}
.button_sliding_bg:hover {
    box-shadow: inset 200px 0 0 0 #31302B;
    color: #FFF;
}
.button_sliding_bg:after {
    content:'';
    display: block;
    position: absolute;
    right: 0;
    bottom: 0;
    width: 0;
    height: 0;
    border-width: 0 0 0 0;
    border-color: transparent transparent #fff transparent;
    border-style: solid;
    border-width: 0 0 32px 30px;
    -webkit-transition: all ease 0.8s;
    -moz-transition: all ease 0.8s;
    transition: all ease 0.8s;
}
<button class="button_sliding_bg">Buttontext</button>