4

I am trying to make some text fade to a new colour and then back to it's original colour.

#sidebar2:target .phonenumber { 
    -o-transition:0.7s;
    -ms-transition:0.7s;
    -moz-transition:0.7s;
    -webkit-transition:0.7s;
    transition:0.7s;
    color: yellow;
}

Currently it just goes to the new colour and stays like that. How can I adapt this code so that is does what I want? Any help is appreciated!

EDIT:

I am using :target so that when a user clicks on a same page link, the part of the text that I'm linking to is highlighted. I would like the text to fade to a different colour and then back again

1
  • Do you have a jsfiddle of what you currently have? Commented Apr 30, 2013 at 12:27

3 Answers 3

4

I'm fairly certain it is not possible to loop a transition, you are able to transition from one state to another but not back again in a single transition.

To achieve the result you are looking for you would use an animation instead.

First set up the animation keyframes:

@keyframes glowyellow {
  0% { color: auto; }
  50% { color: yellow; }
  100% { color: auto; }
}

Then to use this on your element:

#sidebar2:target .phonenumber {
  animation: glowyellow 1.4s linear;
}

Use vendor prefixes to support browsers as you are doing in your example.

Here is a fiddle as an example.

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

4 Comments

Nice one stuart +1 but it's better to define some color or use inherit instead of auto
Thanks, I think inherit will use the color from the parent element, whereas using auto allows you to use any initial color that was previously set for the element. This fiddle shows that using inherit "steals" the parents color definition rather than keeping the elements original color. jsfiddle.net/qzEFL/1
That's perfect thanks Stuart. Just out of interest how well supported is @keyframes?
NP, literature at MDN: developer.mozilla.org/en-US/docs/CSS/…, supported FF, Chrome, Safari, Opera, from a couple of versions back, IE 10
1

Do you mean something like this?

Demo

span {
    color: #000;
    transition: color 1s;
    /* Not using proprietary codes here, you can add it if you need */
}

span:hover {
    color: #aaa;
}

1 Comment

Thanks for the reply. I am using :target so that when a user clicks on a same page link, that part of the page is highlighted. I would like the text to fade to a different colour and then back again
1

8 years late, but there is a "psudo-selector" for visited links: :visited

(It's actually a pseudo class) Just modify the attributes you want from there. No need for animation and transitions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.