Forum Moderators: not2easy

Message Too Old, No Replies

hover effect

         

skylar

2:26 am on Apr 19, 2003 (gmt 0)

10+ Year Member



hi, some code first:

CSS

.feature {display: block; text-decoration: none; height: 100px; width: 100px;}
.feature:hover {text-decoration: underline;}

HTML

<a href="x.html" class="feature">
title<br>
<img src="y.jpg">text here
</a>

OK, what I'm trying to do is create a hover effect that would underline the title only. So if I hover anywhere in the css block, whether on the title, picture or text, I would like for the title only to be underlined.
Seemed like an easy thing to do by just nesting some div's or classes but it doesn't seem to work.
Any ideas? Thx in advance.

nex2k

9:02 am on Apr 19, 2003 (gmt 0)

10+ Year Member



If you give the image an ID and put the following in your CSS:

img#some-id {text-decoration: none;}

Then that will keep the image from being underlined when the link is hovered. The only way I can think of to get the text to not underline is to put it outside the the link.

skylar

8:45 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



The image is not the problem, that doesn't get underlined. As far as the text goes, putting it outside the link would do it of course, but I want it to be part of the block. So if I would hover the text, my title would get underlined.

SinclairUser

9:53 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



Maybe this will help - set anchor to have no decoration for standard display then underline for hover. It works on I.E. 6 just tested it!

a {text-decoration: none}
a:hover {text-decoration: underline}

Let me know if you are still having problems.

SinclairUser

9:57 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



Perhaps I should have explained you are applying the css effect directly to the anchor and not assigning a class to it. That is what makes the difference - let me know if thats clear.

tedster

10:09 pm on Apr 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...if I hover anywhere in the css block, whether on the title, picture or text, I would like for the title only to be underlined.

The text will also take on the hover behavior as well as the title - I can't see how you can get two different hover behaviors inside one anchor tag. You might get an effect like this with DHTML, but not with CSS alone.

mckcd

10:16 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



Sorry clicked submit a little too soon,
See below.

[edited by: mckcd at 10:19 pm (utc) on April 19, 2003]

mckcd

10:18 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



This works but without the block.
If you're using tables try assigning the style "feature" in the <td> tag.

<style type="text/css">
<!--
.feature {display: block; height: 100px; width: 100px;}
.new {text-decoration: none;}
.new:hover {text-decoration: underline;}
.noline {text-decoration: none;}

-->
</style>

</head>
<body>

<a href="you" class="new">title<br>
<img src="y.jpg"><span class="noline">text here</span>
</a>

</body>

</html>

[edited by: mckcd at 10:25 pm (utc) on April 19, 2003]

SinclairUser

10:18 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



Sorry Tedster,

I did not read you post properly!

skylar

3:26 am on Apr 20, 2003 (gmt 0)

10+ Year Member



The text will also take on the hover behavior as well as the title - I can't see how you can get two different hover behaviors inside one anchor tag. You might get an effect like this with DHTML, but not with CSS alone.

I was able to get 2 different behaviours in one anchor tag using the first-line pseudo element:
#feature:first-line {}

This affects my title only which is perfect, but I can't seem to make it work using hover. Is this possible or maybe some other way where only the title as a child element gets the hover effect?

Sinclair and mckcd: thx a lot for the input but it wasn't the precise solution to my problem.

Any other ideas guys?

tedster

5:00 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use first-line - now that's a clever idea. But I tried a few approaches and I had no luck either. For instance - this attempt was no good:

a.new {text-decoration: none;}
a.new:hover {text-decoration: none;}
a.new:hover a.new:first-line {text-decoration:underline;}

I have doubts that we can use first-line to work on hover, because hover is also a pseudo class, just as first-line is a pseudo class. Even if code that combines two pseudo-classes is theoretically valid (which seems dicey to me) I'd be willing to bet that the current browsers won't execute it.

DrDoc

5:30 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried everything I could think of (playing with :before and :after too)... but it seems like there's no pure CSS solution. I think you're forced to wrap some of the text in span tags, like suggested...

DrDoc

5:33 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a.feature:hover:first-line didn't work either...

nex2k

5:56 am on Apr 20, 2003 (gmt 0)

10+ Year Member



I got the effect you wanted, but I had to move the (what I assume to be) description text outside of the link.

CSS:


div.feature { background-color:#ccc; height:100px; width:100px; }
a { text-decoration:none; }
div.feature:hover > a { text-decoration:underline; }
img { background-color:#f1f1f1; width:30px; height:30px; }

XHTML:


<div class="feature">
<a href="#">The Title<br />
<img src="x.jpg" alt="image" /></a>
The all-important plain text.
</div>

And just like all cool CSS effects, it works in Opera and Mozilla, but not IE.

skylar

4:05 am on Apr 21, 2003 (gmt 0)

10+ Year Member



I got the effect you wanted, but I had to move the (what I assume to be) description text outside of the link.

Very true, but there are reasons that I didn't mention in the example that make it important for the text to be inside the anchor tag. If everything fails I would probably need to find a work around for that and resort to your suggestion but I would like to explore options to keep the text in the same tag first.

I have doubts that we can use first-line to work on hover, because hover is also a pseudo class, just as first-line is a pseudo class. Even if code that combines two pseudo-classes is theoretically valid (which seems dicey to me) I'd be willing to bet that the current browsers won't execute it.

So far I haven't had any luck with using 2 pseudo-elements either. I am not very knowledgeable of css2, so I was hoping there would have been an answer there.

skylar

4:10 am on Apr 21, 2003 (gmt 0)

10+ Year Member



And just like all cool CSS effects, it works in Opera and Mozilla, but not IE.

Hmmm, just read that. Scratch my previous comment about resorting to that then :P

SethCall

5:42 am on Apr 21, 2003 (gmt 0)

10+ Year Member



<script type="text/javascript">

UnderlineTitleInThisDiv(){
document.getElementByID("title").style.textDecoration = "underline"
}
NoLineTitleInThisDiv(){
document.getElementByID("title").style.textDecoration = "none"
}
</script>

<div onmouseover="UnderlineTitleInThisDiv();" onmouseout="NoLineTitleInThisDiv();">
<div id="title">Title</div>
<img src="tingtang.png" />
Super Cool Text and Stuff
</div>

Thats the only cross-browser compliant way I know to do it (since IE is hover-unfriendly)