0

Why opacity transition is not effecting on hover, if i just put opacity separately as .4 in text class it works, but it doesn't work with rgba opacity.

ul {
  list-style:none
}

li {
  padding-bottom:15px;
 }
.text {
  color:rgba(13,19,13,.4); // here is initial opacity .4
  transition: opacity 2s cubic-bezier(.4,1,.2,1);
}

.text:hover {
  opacity:.9
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  
  <ul>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>

</ul>
</body>
</html>
Awais
  • 4,752
  • 4
  • 17
  • 40
jsduniya
  • 2,464
  • 7
  • 30
  • 45

4 Answers4

1

You need to set color for transition, once you change opacity within color attribute

ul {
  list-style:none
}

li {
  padding-bottom:15px;
  font-size: 2em;
 }
.text {
  color:rgba(13,19,13,.4);
  transition: color 2s  cubic-bezier(.4,1,.2,1);
}

.text:hover {
  color: rgba(13,119,13,.9);
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  
  <ul>
    <li><a href=""><span class="text">Item</span></a></li>
    <li><a href=""><span class="text">Item</span></a></li>
    <li><a href=""><span class="text">Item</span></a></li>
    <li><a href=""><span class="text">Item</span></a></li>
    <li><a href=""><span class="text">Item</span></a></li>

</ul>
</body>
</html>
Banzay
  • 9,310
  • 2
  • 27
  • 46
0

Here is the solution, in .text class give seperate properety for opacity.

ul {
  list-style:none
}

li {
  padding-bottom:15px;
 }
.text {
  color:rgba(13,19,13,0.4);
  transition: opacity 2s cubic-bezier(.4,1,.2,1);
}

.text:hover {
  cursor:pointer;
  color:rgba(13,19,13,0.9);
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  
  <ul>
    <li><href=""a /><span class="text">Item</span></li>
    <li><href=""a /><span class="text">Item</span></li>
    <li><href=""a /><span class="text">Item</span></li>
    <li><href=""a /><span class="text">Item</span></li>
    <li><href=""a /><span class="text">Item</span></li>

</ul>
</body>
</html>
Ferin Patel
  • 3,424
  • 2
  • 17
  • 49
0

Using opacity only rather then color opacity

ul {
  list-style: none
}

li {
  padding-bottom: 15px;
}

.text {
  opacity: .4;
  transition: opacity 2s cubic-bezier(.4, 1, .2, 1);
}

.text:hover {
  opacity: .9
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>

<body>

  <ul>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>

  </ul>
</body>

</html>

Using color opacity

ul {
  list-style: none
}

li {
  padding-bottom: 15px;
}

.text {
  color: rgba(13, 19, 13, .4);
  transition: color 2s cubic-bezier(.4, 1, .2, 1);
}

.text:hover {
  color: rgba(13, 19, 13, .9);
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>

<body>

  <ul>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>
    <li>
      <href="" a /><span class="text">Item</span></li>

  </ul>
</body>

</html>
Awais
  • 4,752
  • 4
  • 17
  • 40
  • Looks your demo not working, i don't see any transition effect on hover. – jsduniya Apr 02 '20 at 05:51
  • 1
    @jsduniya Sorry my bad did't remember to change opacity transition to color in color rgba hover case, Update my ans please check – Awais Apr 02 '20 at 06:03
0

use the color property on transition and on :hover use color:rgba(13,19,13,0.9);

ul {
  list-style:none
}

li {
  padding-bottom:15px;
 }
.text {
  color:rgba(13,19,13,0.4);
  transition: color 2s cubic-bezier(.4,1,.2,1);
}

.text:hover {
  color:rgba(13,19,13,0.9);
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  
  <ul>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>
    <li><a href="#" /><span class="text">Item</span></li>

</ul>
</body>
</html>
Raydoan Anik
  • 219
  • 2
  • 15