CSS过渡,带按钮,不覆盖文本

Peg*_*ues 2 html css

任何人都可以通过使用按钮帮助我解决问题::after吗?我::after对悬停按钮的内容位于文本上方有问题。

JSFiddle:https://jsfiddle.net/pegues/yh4g2cme/

.button {
  position: relative;
  margin: 10px;
  padding: 16px 18px;
  color: #fff;
  font-family: Arial, Helvetica, Sans-serif;
  font-size: 1.00rem;
  line-height: 1.35rem;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  border: 0 none;
  background-color: #556f6e;
  -webkit-transition: all 0.20s ease-in-out;
  -moz-transition: all 0.20s ease-in-out;
  -ms-transition: all 0.20s ease-in-out;
  -o-transition: all 0.20s ease-in-out;
  transition: all 0.20s ease-in-out;
}
.button span {
  position: relative;
  z-index: 1;
  font-weight: inherit;
}
.button::after {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  display: block;
  width: 4px;
  height: 100%;
  content: ' ';
  background-color: #7cab4c;
  -webkit-transition: all 0.20s ease-in-out;
  -moz-transition: all 0.20s ease-in-out;
  -ms-transition: all 0.20s ease-in-out;
  -o-transition: all 0.20s ease-in-out;
  transition: all 0.20s ease-in-out;
}
.button:hover::after {
  width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<br/>
<a class="button" href="#" title="" target="_blank"><span>With Span</span></a>
<a class="button" href="#" title="" target="_blank">Without Span</a>
Run Code Online (Sandbox Code Playgroud)

如果我span在锚标记内包裹文本,则可以添加position: relative; z-index: 1;到该跨度中,问题就解决了。但我无法span.button整个网站的所有锚定标记中都放一个。

dgk*_*nca 5

我用 ::before

.button {
  position: relative;
  margin: 10px;
  padding: 16px 18px;
  color: #fff;
  font-family: Arial, Helvetica, Sans-serif;
  font-size: 1.00rem;
  line-height: 1.35rem;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  border: 0 none;
  -webkit-transition: all 0.20s ease-in-out;
  -moz-transition: all 0.20s ease-in-out;
  -ms-transition: all 0.20s ease-in-out;
  -o-transition: all 0.20s ease-in-out;
  transition: all 0.20s ease-in-out;
}
.button::before {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background-color: #556f6e;
  z-index: -2;
}
.button::after {
  content: ' ';
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 4px;
  height: 100%;
  background-color: #7cab4c;
  z-index: -1;
  -webkit-transition: all 0.20s ease-in-out;
  -moz-transition: all 0.20s ease-in-out;
  -ms-transition: all 0.20s ease-in-out;
  -o-transition: all 0.20s ease-in-out;
  transition: all 0.20s ease-in-out;
}
.button:hover::after {
  width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<br />
<a class="button" href="#" title="" target="_blank"><span>With Span</span></a>
<a class="button" href="#" title="" target="_blank">Without Span</a>
Run Code Online (Sandbox Code Playgroud)

我也只有background-size财产。没有伪元素。

.button {
  position: relative;
  margin: 10px;
  padding: 16px 18px;
  display: inline-block;
  color: #fff;
  font-family: Arial, Helvetica, Sans-serif;
  font-size: 1.00rem;
  line-height: 1.35rem;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  border: 0 none;
  background: linear-gradient(#7cab4c, #7cab4c), #556f6e;
  background-size: 4px 100%;
  background-repeat: no-repeat;
  transition: all 0.20s ease-in-out;
}
.button:hover {
  background-size: 100% 100%, 100% 100%;
}
Run Code Online (Sandbox Code Playgroud)
<a class="button" href="#" title="" target="_blank">Read More</a>
Run Code Online (Sandbox Code Playgroud)