I have a case where I must write inline CSS code, and I want to apply a hover style on an anchor.
How can I use a:hover
in inline CSS inside the HTML style attribute?
E.g. you can't reliably use CSS classes in HTML emails.
I have a case where I must write inline CSS code, and I want to apply a hover style on an anchor.
How can I use a:hover
in inline CSS inside the HTML style attribute?
E.g. you can't reliably use CSS classes in HTML emails.
According to your comments, you're sending a JavaScript file anyway. Do the rollover in JavaScript. jQuery's
$.hover()
method makes it easy, as does every other JavaScript wrapper. It's not too hard in straight JavaScript either.This is pretty late in the game, but when would you use JavaScript in an HTML Email? For example, at the company I currently work for (rhymes with Abodee), we use the lowest common denominator for most email marketing campaigns – and JavaScript is just not being used. Ever. Unless you are referring to some kind of pre-processing.
As mentioned in a related post: "Lotus Notes, Mozilla Thunderbird, Outlook Express, and Windows Live Mail all seem to support some sort of JavaScript execution. Nothing else does."
Link to the article from which this was taken: [http://en.wikipedia.org/wiki/Comparison_of_e-mail_clients]
Also, how would hovering translate to mobile devices? That's why I like the answer from above:
Long answer: you shouldn't.
If anyone has more insights into this subject, please feel free to correct me. Thank you.
You can do this. But not in inline styles. You can use
onmouseover
andonmouseout
events:So this isn't quite what the user was looking for, but I found this question searching for an answer and came up with something sort of related. I had a bunch of repeating elements that needed a new color/hover for a tab within them. I use handlebars, which is key to my solution, but other templateing languages may also work.
I defined some colors and passed them into the handlebars template for each element. At the top of the template I defined a style tag, and put in my custom class and hover color.
Then I used the style in the template:
You may not need the
!important
You can get the same effect by changing your styles with JavaScript in the
onMouseOver
andonMouseOut
parameters, although it's extremely inefficient if you need to change more than one element:Also, I can't remember for sure if
this
works in this context. You may have to switch it withdocument.getElementById('idForLink')
.As pointed out, you cannot set arbitrary inline styles for hover, but you can change the style of the hover cursor in CSS using the following in the appropriate tag: