css 悬停颜色从右侧变化到 div 的 25%

css hover color change from right till 25% of the div

我里面有一个 div 元素 我有一些链接。我希望 div 的颜色在鼠标悬停时改变,而不是整个宽度的长度,而只是 div.

的 25%

当我使用悬停属性时,它会改变整个 div 的颜色。 还请建议我应该放置哪个标签我的悬停属性 - span 标签或标签。

如何在颜色变化期间获得平滑的过渡动画?

.c-label {
  display: inline-block;
  text-align: left;
}

.cloud-label {
  display: inline-block;
  float: left;
  margin: 5px 0;
  opacity: 1;
  width: 50%;
  line-height: 1.2;
  font-size: 120%;
  text-align: left;
}

.cloud-label a {
  transition: all 0.5s;
  background: #000;
  border-radius: 3px;
  color: #fff;
  display: block;
  font-size: 14px;
  padding: 7px 20px;
  position: relative;
  margin-left: 20px;
  text-decoration: none;
  transition: color .15s linear;
  -webkit-transition: color .15s linear;
  -moz-transition: color .15s linear;
}

.cloud-label a::before {
  content: "";
  display: block;
  border-style: solid;
  border-color: transparent #138D89 transparent transparent;
  border-width: 15.2px;
  width: 0px;
  left: 0px;
  position: absolute;
  margin-left: -29px;
  margin-top: -15px;
  top: 50%;
}

.cloud-label a::after {
  content: "";
  display: block;
  position: absolute;
  width: 8px;
  height: 8px;
  background-color: #fff;
  border-radius: 50%;
  top: 50%;
  margin-top: -4px;
  left: -3px;
}

.cloud-label :hover {
  background-color: #138D89;
}
<div class="c-label">
  <span class="cloud-label">
<a href="#" rel="nofollow">Gadgets</a>
</span>
</div>

not to full length of width but only 25% of the div

您可以为此使用 linear-gradient

Also please suggest which tag I should put my hover properties- span tag or a tag

原则上不需要附加标签

How can I get a smooth transition animation during the colour change?

悬停时,需要将属性background-position从一侧改变到另一侧(例如从左到右)。

结果

.link {
  position: relative;
  display: inline-block;
  margin-left: 10px;
  padding: 5px 10px;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  background: linear-gradient(to left, #138D89 25%, #000 25%) left / 135% 100% no-repeat;
  transition: 0.3s;
}

.link:hover {
  background: linear-gradient(to left, #138D89 25%, #000 25%) right / 135% 100% no-repeat;
}

.link::before {
  content: "";
  position: absolute;
  top: 0;
  right: 100%;
  border-right: 15px solid #138D89;
  border-top: 13px solid transparent;
  border-bottom: 15px solid transparent;
}

.link::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  box-sizing: border-box;
  background: #fff;
  border-radius: 50%;
}
<a class="link" href="">Lorem ipsum dolor sit amet.</a>

CodePen

上的相同代码