如何改变以使其从左下角开始而不是从右下角开始?

时间:2016-02-18 12:08:34

标签: css

我在悬停时遇到了这个codepen的对角线填充div,我的问题是如何从左下角而不是右下角开始填充,这可能是一个简单的任务,但我不知道,任何帮助将不胜感激。

.diagonal {
    position: relative;
    line-height: 50px;
    background: #67809F;
    color: white;
    border: none;
    font-weight: bold;
    font-family: 'Open Sans', sans-serif;
    overflow: hidden;
    z-index: 1;
    padding: 0px;
  }

.diagonal:after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 500%;
    height: 1000%;
    background: #34495E;
    z-index: -1;
    transform-origin: 0% 0%;
    transform: translateX(calc(20% - 25px)) translateY(10%) rotate(-45deg);
    /transform: translateY(10%) translateX(16%) rotate(-45deg);
    transition: transform .3s;
  }

.diagonal:hover::after {
    transform: translateY(10%) translateX(-25px) rotate(-45deg);
  }

http://codepen.io/kzf/pen/LEEzew?editors=1100

1 个答案:

答案 0 :(得分:1)

将原始状态和悬停状态下的translateY(10%)更改为translateY(0%)

https://jsfiddle.net/nko2u23j/

.demo {
	text-align: center;
	margin-top: 150px;
}

.mt {
  margin-top: 20px;
}

.small {
  width: 120px;
}

.medium {
  width: 160px;
}

.large {
  width: 230px;
}

.extra-large {
  width: 360px;
}

.diagonal {
  position: relative;
  line-height: 50px;
  background: #67809F;
  color: white;
  border: none;
  font-weight: bold;
  font-family: 'Open Sans', sans-serif;
  overflow: hidden;
  z-index: 1;
  padding: 0px;
}
.diagonal:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 500%;
  height: 1000%;
  background: #34495E;
  z-index: -1;
  transform-origin: 0% 0%;
  transform: translateX(-25px) translateY(0%) rotate(-45deg);
  /transform: translateY(10%) translateX(16%) rotate(-45deg);
  transition: transform .3s;
}
.diagonal:hover::after {
  transform: translateY(0%) translateX(calc(20% - 25px)) rotate(-45deg);
}
  
<div class="demo">
  
  <button class="mt small diagonal">Click me!</button>
  <br>
  <button class="mt medium diagonal">Click me!</button>
  <br>
  <button class="mt large diagonal">Click me!</button>
  <br>
  <button class="mt extra-large diagonal">Click me!</button>

</div>