-1

I have the following code:

z {
  color: #0563bb;
}

z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px, 32px, 25px, -8px rgba(0, 0, 0, .2),
}
 <p>Hi there <z>This is the text that needs the hover animation</z>

Why doesn't the animation seem to work? Is it because its text or am I doing something wrong?

2
  • What animation? The code written will be applied immediately without any transition or animation. Commented Jul 17, 2021 at 22:03
  • The box shadow value is also invalid. Commented Jul 17, 2021 at 22:07

4 Answers 4

1

The problem there is you are using transform but not transition. This way the text jumps to the next state without an animation. This should fix your problem:

z {
  color: #0563bb;
  display:inline-block;
  trasform: translate(0, 0);
  transition: all 0.8s linear;
}

z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px 32px 25px -8px rgba(0, 0, 0, .2);
  transition: all 0.8s linear;
}
<p>Hi there <z>This is the text that needs the hover animation</z></p>

You should also remove the comas from the box-shadow value.

Sign up to request clarification or add additional context in comments.

Comments

1

It just needs a block-style display, as in display:inline-block; Additionally, I added a transition on the element for a little animation.

Note: Your box-shadow values were not valid. I corrected them, but take a look at this: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow

Thanks @evolutionxbox for the guidance and extra set of eyes

z {
  color: #0563bb;
  display:inline-block;
  transition: transform .3s;
}

z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px 32px 25px 8px rgba(0, 0, 0, .2);
}
<p>Hi there <z>This is the text that needs the hover animation</z></p>

2 Comments

The box shadow has an invalid property value. There's also still no animation?
Thanks @evolutionxbox for the guidance and extra set of eyes
1

Your box-shadow property value is invalid. Remove the commas:

z {
  color: #0563bb;
  display:inline-block;
}

z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px 32px 25px -8px rgba(0, 0, 0)  /* percentage removed for demonstration */
}
<p>Hi there <z>This is the text that needs the hover animation</z>

If you want to make the changes "animate", simply specify a transition duration:

z {
  color: #0563bb;
  display:inline-block;
  transition:0.5s;
}

z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px 32px 25px -8px rgba(0, 0, 0)  /* percentage removed for demonstration */
}
<p>Hi there <z>This is the text that needs the hover animation</z>

Comments

0

There is no Element have name <z> in HTML, You Should not Put , in the last Line so The right Code in HTML mey be Lik eThis:

<p>Hi there <div class="z">This is the text that needs the hover animation</div></p>

and CSS Like This :

.z {
  color: red;
  display: inline-block;
 }

.z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px, 32px, 25px, -8px rgba(0, 0, 0, .2);
}

Or You should add Closing Tag For p Tag and Remove , in CSS Code and Replace it with ;. So Your Code Mey Be Like This:

<p>Hi there <z>This is the text that needs the hover animation<z></p>

and CSS Like This:

z {
  color: red;
  display: inline-block;
 }

z:hover {
  transform: translate(0, -7px);
  box-shadow: 0px, 32px, 25px, -8px rgba(0, 0, 0, .2);
}

2 Comments

There's not a z element, but HTML is tolerant enough to allow it.
I know But I talk about the best syntax for his code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.