Forum Moderators: not2easy
I have a string embedded within h1 tags (which I would like to keep as is) that has a link for one of the words. The link takes on a different style (as defined in the stylesheet) than the rest of the string. Is there anyway to cancel all styles for that particular link, so that it stays within the same style as the h1 tag? Please keep in mind, that I can't change the default anchor class.
Any help will be appreciated.
Thanks.
-R
<style>
a { font : normal 8pt Verdana; color : #000000; text-decoration:underline; }
a:hover { font : normal 8pt Verdana; color : #993300; text-decoration:none; }
a.bold { font : bold 8pt Verdana; color : #000000; text-decoration:underline; }
a:hover.bold { font : bold 8pt Verdana; color : #626B21; text-decoration:none; }
a.test:link {}
a.test:visited {}
a.test:active {}
a.test:hover {}
</style>
<h1>this is a <a href="#" class="test">sample</a> test</h1>
is that the same as class test?
<style>
a { font : normal 8pt Verdana; color : #000000; text-decoration:underline; }
a:hover { font : normal 8pt Verdana; color : #993300; text-decoration:none; }
a.bold { font : bold 8pt Verdana; color : #000000; text-decoration:underline; }
a:hover.bold { font : bold 8pt Verdana; color : #626B21; text-decoration:none; }
a.test{}
a.test:link {}
a.test:visited {}
a.test:active {}
a.test:hover {}
</style>
firstly there is an error in your CSS
a.bold { font : bold 8pt Verdana; color : #000000; text-decoration:underline; }
a:hover.bold { font : bold 8pt Verdana; color : #626B21; text-decoration:none; }
should be a.bold:hover the psuedo class(hover in this case) should always be added at the end after any class names or ID's.
I realise that's not your question here though ;)
If you remove the font-size and family from your links (they should inherit from the surrounding text) You could apply the font size/family to the <body>, <div> <p>..etc not the anchors themselves.
then without even adding a classname inside your <h1> or <h2> tags they will inherit the size/family from them. If you also want to change the colors, decoration or hover effects from links inside these tags. You still do not need a extra class name just be sure to target them a little more specifically..
To specifically target the ones inside your heading tags try this:
body {font-size: 8pt; font-family: verdana;} /* put this on the parent element, I just used body for this example */a { color : #000000; text-decoration:underline; }
a:hover { color : #993300; text-decoration:none; }h1 a, h2 a {color : #000000; text-decoration:none; }
h1 a:hover, h2 a:hover { color : #993300; text-decoration: underline; }HTML:
<p>this is a <a href="foo.htm">sample</a> link</p>
<h1>this is a <a href="foo.htm">sample</a> link</h1>
<h2>this is a <a href="foo.htm">sample</a> link</h2>
I swapped the underlines for testing..
as long as you re-define all the rules that you had in the general anchor style you are in effect cancelling it out, the font-size and family will inherit from their parents.
If you want to leave the decoration the same you wouldn't need to re-define it as it will inherit from the general anchor style.
So instead of cancelling inheritance (which goes against CSS) then you are using it and the code is smaller too ;)
Suzy
<added>HTML code</added>