4

I have a simple Css rule like so:

strong a:hover {
text-decoration: none;
}

This works for the following HTML:

<strong>
<a href="www.stackoverflow.com">Go to website</a>
</strong>

The problem is the Wysiwyg within the CMS i am using often puts the code in like so:

<a href="www.stackoverflow.com"><strong>Go to website</strong></a>

My css rule then doesnt work. Is there are pure Css solution?

Thanks Al

higgsy
  • 1,991
  • 8
  • 30
  • 47

5 Answers5

6

What you're trying to do isn't supported in CSS - you can't style the parent. A better approach here might be to add a class to the link:

<a href="http://www.stackoverflow.com" class="ImportantLink">Go to website</a>

CSS:

a.ImportantLink { font-weight:bold; }
a.ImportantLink:hover { text-decoration: none; }

That way the link can easily be styled. <strong> may be semantically wrong if you use it just to style the link, and not to emphasize the text (though, that might be less important, to be honest)

Working Example: http://jsbin.com/ekuza5

Kobi
  • 135,331
  • 41
  • 252
  • 292
2

use

a:hover strong 
{
  text-decoration:none;
}
baikho
  • 5,203
  • 4
  • 40
  • 47
Ujjwal Manandhar
  • 2,194
  • 16
  • 20
2

This should work:

.hrefspan a:hover, strong {
text-decoration: none;}

<span class="hrefspan"><a>...</a></span>

By putting it in a span and applying the css only to the content of that span it will not affect other href's or strong's.

Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101
0

since you have define rule strong a:hover indicates rules to be applied to the a tag which is present inside strong html tag

Poonam
  • 4,591
  • 1
  • 15
  • 20
0

So the bit you actually want to change is the underling of the anchor

a:hover { text-decoration:none; }

If you want to have this only affect particular links on the page then apply classes to them.

<a class="notunderlined" href="http://www.stackoverflow.com"><strong>Foobar</strong></a>

a.notunderlined:hover { text-decoration:none; }
Evil Andy
  • 1,748
  • 1
  • 14
  • 19