tags:

views:

426

answers:

7

I'm going to use such CSS table for my menu:

.menu {text-decoration:underline;}
.menu a:link {text-decoration:none; color:#0202C0}
.menu a:active {text-decoration:none; color:#0202C0}
.menu a:visited {text-decoration:none; color:#0202C0}
.menu a:hover {text-decoration:underline; color:#0099FF}

but while trying to apply it to the document

<span class="menu">
   Some underlined text came here... 
   <a href="...">this text should not be underlined until mouse on!</a>
</span>

I found unexpected behavior: link text always stay underlined. What I'm doing wrong? Could it depends on browser (I'm using Mozilla Firefox 3.5.6, probably IE 6.0 display it properly)? If so, how can I rely CSS at all? What should I use to substitute it?

(In fact usually I got learned new programming languages very quickly and never had any problems with programing basis until I started HTML and CSS. Either I'm incompatible with it or its features was never recounted well enough.)

A: 

Have you tried adding:

.menu a {text-decoration:none}

before all the other rules? Just to establish a default which is then overridden by the a:hover rule.

slebetman
I have tried now, but no reaction...
Nick
What about trying this in other cases? Add a `<span>` within the menu span, and then try `.menu span {text-decoration:none;}`. If that doesn't work, there may be a larger issue.
Ipsquiggle
This is strange. It should work. Are you sure there are no other css rules interfering?
slebetman
I tried, it worked if inside .menu span with .menu span {text-decoration:none} I put other text into inner span with {text-decoration:underline}. Thank you, in fact I supposed so... Just I wish to know how to override inherited property.
Nick
To slebetman: thanks you, it really strange.
Nick
A: 

Increase the "weight" of the selector by adding more parent elements before it:

body span a        { text-decoration:none; }
body span a:hover  { text-decoration:underline; }

Increasing the weight should remedy the issue...

.menu {text-decoration:underline;}
body .menu span a:link {text-decoration:none; color:#0202C0}
body .menu span a:active {text-decoration:none; color:#0202C0}
body .menu span a:visited {text-decoration:none; color:#0202C0}
body .menu span a:hover {text-decoration:underline; color:#0099FF}
Alexander
But it could affect main (not of class menu) text or I haven't understood you properly? Same way typing .menu body span a {text-decoration:none;} result nothing.
Nick
body refers to the DOM element body. your menu should be inside of the body. If so, then you will be able to add more weight to the specific selector, in this case the <a></a> tag that you (don't) want underlined.visit:http://www.w3.org/TR/CSS2/cascade.html
Alexander
Here's a summary on Selector "Weight" and "Specificity"- http://www.webteacher.ws/2008/05/19/tip-calculate-the-specificity-of-css-selectors/
Alexander
A: 

I'd recommend using the Firebug plugin for firefox, it's a lifesaver! This will let you see which styles are being applied to your elements.

Fermin
This should be a comment, as it doesn't address a specific solution for the OP.
Jonathan Sampson
Thanks a lot for this suggestion. Now I applied this plug-in to my example and found that <a>'s "text-decoration" style both <a> own and inherited is displayed strikethrough. Would like to know why...
Nick
And the markdown is for...
Fermin
sorry, it wasn't me, I didn't markdown any answer there... I really thankful for your advise.
Nick
A: 

Remove .menu { text-decoration:underline } I would suggest the alternative:

.menu a { text-decoration:none; color:#0202C0 }
.menu a:hover { text-decoration:underline; color:#0099FF }
Jonathan Sampson
Seriously, couldn't you see that it would left main (not <a>) text not underlined as I expected to be.
Nick
Nick, you misunderstood me.
Jonathan Sampson
Sorry maybe i really do not understand your advice properly (but really it was not who -1 your answer)... In my example <span class="menu">text1<a href="link1">text2</a>text3</span> I want text1 and text3 be underlined.
Nick
A: 

Ensure that it is a valid link inside of the href. If you do not supply this style:

.menu a, .menu a:link{my styles}

and the href has no contents, some browsers will not treat it as a link and do default text rendering. For example, <a href=""> will not take on the style of .menu a:link, it will go to the default .menu styles because there is no link and it is not rendered as such by some browsers.

Of course, cover your bases by including the bare a in your selector.

Additionally, make sure you end those color styles with semicolons for proper CSS syntax.

neatlysliced
It has proper link inside... Even if have no any link my Firefox still apply color properly and change it when mouse on, only underline could not be removed.
Nick
Are you applying underlines elsewhere in the document? Perhaps it is inheriting from something else, and .menu and .menu a is insufficient to override it. Google CSS Specificity to understand further - nice tutorial here http://css-tricks.com/specifics-on-css-specificity/
neatlysliced
Oh, no, I do not underlining anything else, I cleaned the example exactly as you see it in question.
Nick
You're right, I've never seen this before. It occurred in IE for me as well. The solution by icabod may be your best bet. I'd +1 your question if I had a better reputation, this is crazy!
neatlysliced
+1  A: 

After a quick play with some CSS, a workaround (which is horrid, but does work) would be to do the following in your CSS:

.menu span {text-decoration:underline;}

... in place of the first line of your sample CSS. Then in the HTML do the following:

<span class="menu">
    <span>Some underlined text came here...</span>
    <a href="...">this text should not be underlined until mouse on!</a>
    <span>Some more underlined text came here...</span>
</span>

It's far from being perfect, but is the best I can come up with for the moment.

icabod
Yeah, thanks a lot, it work as I told before in the answer to Ipsquiggle's comment of slebetman's answer. It is solution, but it is partial, such strange behavior could happen any time. Moral: never swap understanding of default and emphasized text's from standard meaning in html formatting. It is not LOL.
Nick
A: 

Have you tried this?

.menu {text-decoration:underline;}
body .menu span a:link {text-decoration:none; color:#0202C0}
body .menu span a:active {text-decoration:none; color:#0202C0}
body .menu span a:visited {text-decoration:none; color:#0202C0}
body .menu span a:hover {text-decoration:underline; color:#0099FF}
Alexander
You shouldn't have to change your html to accommodate the behavior you are trying to exhibit...
Alexander