473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to prevent hover of anchored words?

Hello,

I have a page with a usual mouseover link highlight effect eg.:

a:hover {color: #ff0000; text-decoration: none;}

I also have some anchor links such as:

<a href="#jalfrezi">Jalfrezi</a> | <a href="#vindaloo">Vindaloo</a> | etc...

<IMG> ...

<a name="Jalfrezi"><h2>Jalfrezi</h2></a>
Into a pot of boiling water, drop the cauliflower, carrots, bell pepper, and
green peas and blanch for 3 to 5 minutes etc...

<a name="vindaloo"><h2>Vindaloo</h2></a>
In a wok, fry the onions over low to moderate heat in the oil until they are
carmelized. Add the chicken, increase the heat, and stir fry until the
chicken turns white.

---

Now not only the "Jalfrezi" and "Vindaloo" links highlight on the page, but
also the achors (H2's) themselves, without the mouse turning into a
pointer. Is there an easy way to prevent that?
Nov 23 '05 #1
24 2239
Fred Lock wrote on 13 nov 2005 in
comp.infosystems.www.authoring.stylesheets:
a:hover {color: #ff0000; text-decoration: none;}

I also have some anchor links such as:

<a href="#jalfrezi">Jalfrezi</a> | <a href="#vindaloo">Vindaloo</a> |
etc...

<IMG> ...

<a name="Jalfrezi"><h2>Jalfrezi</h2></a>


<style>
a.yes:hover {color: #ff0000; text-decoration: none;}
a.no:hover {background-color:yellow;}
</style>

<a href="#Jalfrezi" class='yes'><h2>Jalfrezi</h2></a>
<a href="Jalfrezi" class='no'><h2>Jalfrezi</h2></a>

<a name="Jalfrezi"><h2>This is not hoverable in IE</h2></a>
[try onmouseover/onmouseout javascript/css]

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #2
On Sun, 13 Nov 2005, Fred Lock wrote:
I have a page with a usual mouseover link highlight effect eg.:

a:hover {color: #ff0000; text-decoration: none;}
[...]
Now not only the "Jalfrezi" and "Vindaloo" links highlight on the
page, but also the achors (H2's) themselves, without the mouse
turning into a pointer.
Sure - that's what you're asking for in your selector, after all.
Is there an easy way to prevent that?


If you refer to the relevant part of the spec:

http://www.w3.org/TR/CSS21/selector....pseudo-classes

it should be obvious. Make your selectors more-specific:

a:link:hover, a:visited:hover etc.

(Remember that for selectors of equal specificity, order matters.)

have fun.
Nov 23 '05 #3
rf
Fred Lock wrote:
Hello,

I have a page with a usual mouseover link highlight effect eg.:

a:hover {color: #ff0000; text-decoration: none;}

I also have some anchor links such as:

<a href="#jalfrezi">Jalfrezi</a> | <a href="#vindaloo">Vindaloo</a> | etc...

<IMG> ...

<a name="Jalfrezi"><h2>Jalfrezi</h2></a>
Into a pot of boiling water, drop the cauliflower, carrots, bell pepper, and
green peas and blanch for 3 to 5 minutes etc...

<a name="vindaloo"><h2>Vindaloo</h2></a>
In a wok, fry the onions over low to moderate heat in the oil until they are
carmelized. Add the chicken, increase the heat, and stir fry until the
chicken turns white.

---

Now not only the "Jalfrezi" and "Vindaloo" links highlight on the page, but
also the achors (H2's) themselves, without the mouse turning into a
pointer. Is there an easy way to prevent that?


This is invalid HTML anyway. You cannot have a block element (h2) inside an
inline element (a).

--
Cheers, Richard.
If you are reading this using google groups then also read this:
http://www.safalra.com/special/googlegroupsreply/ if you have not done so
already. If you reply to this post without correct quoting and attribution,
as per the above, I, and others, may just totally ignore you.
Nov 23 '05 #4
Fred Lock wrote:
<a name="Jalfrezi"><h2>Jalfrezi</h2></a>
<h2><a name="Jalfrezi"></a>Jalfrezi</h2>
<a name="vindaloo"><h2>Vindaloo</h2></a>
<h2><a name="vindaloo"></a>Vindaloo</h2>
Is there an easy way to prevent that?


Yup.

--
-bts
-Warning: I brake for lawn deer
Nov 23 '05 #5
> <a href="Jalfrezi" class='no'><h2>Jalfrezi</h2></a>

Yes thanks. It works, and no need for the yes class.
<a name="Jalfrezi"><h2>This is not hoverable in IE</h2></a>


I don't care about IE for non-essential effects like hover. The browser
should die out in the next 2-3 years anyway, and I hope the Microsoft
Corporation soon thereafter.

Nov 23 '05 #6
> This is invalid HTML anyway. You cannot have a block element (h2) inside
an inline element (a).


In that case I better do:

<h2><a name=""jalfrezi">Jalfrezi</a></h2>

It sounds like a useless CSS rule and I'm not sure what difference it makes
in the real world but I guess I will comply.

Nov 23 '05 #7
> <h2><a name="vindaloo"></a>Vindaloo</h2>

I figured this works too, but I guess it isn't valid or something.

Nov 23 '05 #8
Fred Lock <fr******@mailinator.net> wrote:
<a name="Jalfrezi"><h2>Jalfrezi</h2></a>


This is invalid. An inline element (like <A>) can not contain
block elements (like <H2>). So in principle the <A> element
would end directly before the next block element which would
result in the following "virtual" code:

<a name="Jalfrezi"></a><h2>Jalfrezi</h2>

Though most browsers wouldn't handle it this way, you should
nevertheless fix these errors. This is the correct nesting:

<h2><a name="Jalfrezi">Jalfrezi</a></h2>

--
Alexander
Nov 23 '05 #9
> <h2><a name="Jalfrezi">Jalfrezi</a></h2>

Yes that's what I opted for, adding the class="no" to the anchor and
specifying it same color on hover as the text when its not hovered. Thanks.
Nov 23 '05 #10
Fred Lock skrev:
<h2><a name="vindaloo"></a>Vindaloo</h2>


I figured this works too, but I guess it isn't valid or something.


Use id instead.

<h2 id="vindaloo">Vindaloo</h2>
--
Topposter du svar, dvs. skriver dit svar over det citerede,
så ryger du på min ignoreringsliste.
Svar under det du citerer og citer kun det du svarer på - tak.
http://usenet.dk/netikette/citatteknik.html
Nov 23 '05 #11
..oO(Fred Lock)
This is invalid HTML anyway. You cannot have a block element (h2) inside
an inline element (a).
In that case I better do:

<h2><a name=""jalfrezi">Jalfrezi</a></h2>


In recent browsers this works as well:

<h2 id="jalfrezi">Jalfrezi</h2>
It sounds like a useless CSS rule
It has nothing to do with CSS, it's an HTML rule that inline elements
can only contain other inline elements or text. And it does make sense,
simply because of the differences in how block-level and inline elements
are handled and rendered.

7.5.3 Block-level and inline elements
http://www.w3.org/TR/html401/struct/global.html#h-7.5.3
and I'm not sure what difference it makes
in the real world


Invalid code is invalid code.

Micha
Nov 23 '05 #12
..oO(Fred Lock)
<h2><a name="Jalfrezi">Jalfrezi</a></h2>


Yes that's what I opted for, adding the class="no" to the anchor and
specifying it same color on hover as the text when its not hovered. Thanks.


No need for a class there:

h2 a:hover {...}

does the same.

Micha
Nov 23 '05 #13
On Sun, 13 Nov 2005, Fred Lock in an unattributed quote:
This is invalid HTML anyway. You cannot have a block element (h2)
inside an inline element (a).

which came from "rf". I must admit I'd missed that error, but the
answer which I gave will work just as well when the error is
corrected.
In that case I better do:

<h2><a name=""jalfrezi">Jalfrezi</a></h2>
You'd better count your quotes. But otherwise that's fine, and
compatible with a wide range of browsers (including any there might be
which still require non-null content in the anchor element).
It sounds like a useless CSS rule
What's "it"? The error raised by rf was an HTML syntax rule, which
you'd do well to check and correct (e.g with the W3C HTML validator)
before asking the group for assistance. It's demeaning for humans to
be asked to do the hack work of a computer.
and I'm not sure what difference it makes in the real world


That sounds like a good reason for sticking to the rules. You'd do
well to make friends with the validators and checkers.
Nov 23 '05 #14
Fred Lock wrote:

[Beauregard said:]
<h2><a name="vindaloo"></a>Vindaloo</h2>


I figured this works too, but I guess it isn't valid or something.


Why wouldn't it be valid? It validates on my pages. Use an empty <a
element if you don't want to worry about hover stuff.

(Please don't trim attributes of the quotes. Thanks.)

--
-bts
-Warning: I brake for lawn deer
Nov 23 '05 #15
On Sun, 13 Nov 2005, Michael Fesser wrote:
.oO(Fred Lock)
<h2><a name="Jalfrezi">Jalfrezi</a></h2>
Yes that's what I opted for, adding the class="no" to the anchor
and specifying it same color on hover as the text when its not
hovered. Thanks.


No need for a class there:


True
h2 a:hover {...}

does the same.


AIUI he does *not* want hover to take effect on the anchors. He was
only getting it because his selector a:hover was too broad - he only
wanted it to take effect for links. The solution is to use a
more-specific selector *for the links*.

The purpose-designed answer is a:link:hover (and maybe a:visited:hover
if he wants that too). All this foolery with extra classes and
additional context selectors is just distraction from the general
solution.
Nov 23 '05 #16
> h2 a:hover {...}

Even better! and obvious. Thanks.
Nov 23 '05 #17
> be asked to do the hack work of a computer.

Yes its true, but then again, a validator won't give me any opinions.
well to make friends with the validators and checkers.


Will comply.
Nov 23 '05 #18
..oO(Alan J. Flavell)
AIUI he does *not* want hover to take effect on the anchors.
Yep, it was just in reply to his way of "removing" the hover on the
anchors.
He was
only getting it because his selector a:hover was too broad - he only
wanted it to take effect for links. The solution is to use a
more-specific selector *for the links*.


ACK

a[href]:hover would also do it, if there wouldn't be IE ...

Micha
Nov 23 '05 #19
It's a matter of taste, isn't it? I don't see the point of your
fundamentalistic view...

And here comes the quote I just replied to - sorry, but you're literally
begging for it: ;-)

"Knud Gert Ellentoft" ha scritto...
Topposter du svar, dvs. skriver dit svar over det citerede,
så ryger du på min ignoreringsliste.
Svar under det du citerer og citer kun det du svarer på - tak.
http://usenet.dk/netikette/citatteknik.html


Regards,
Matthias
Nov 23 '05 #20
"Fred Lock" <fr******@mailinator.net> wrote in message
news:dl*************@news.t-online.com...
<a href="Jalfrezi" class='no'><h2>Jalfrezi</h2></a>


Yes thanks. It works, and no need for the yes class.
<a name="Jalfrezi"><h2>This is not hoverable in IE</h2></a>


I don't care about IE for non-essential effects like hover. The browser
should die out in the next 2-3 years anyway, and I hope the Microsoft
Corporation soon thereafter.


Wishful thinking
Nov 23 '05 #21
> Wishful thinking

Positive thinking!
Nov 23 '05 #22
In article <dl*************@news.t-online.com>,
Fred Lock <fr******@mailinator.net> wrote:
<h2><a name="vindaloo"></a>Vindaloo</h2>


I figured this works too, but I guess it isn't valid or something.


I had a note that some user agents may not find an empty anchor. I
don't know which browsers that might be, but I would prefer not to
chance it.

--
http://www.ericlindsay.com
Nov 23 '05 #23
In article <ta********************************@dtext.news.tel e.dk>,
Knud Gert Ellentoft <el*******@mail.tele.invalid> wrote:
Fred Lock skrev:
<h2><a name="vindaloo"></a>Vindaloo</h2>


I figured this works too, but I guess it isn't valid or something.


Use id instead.

<h2 id="vindaloo">Vindaloo</h2>


I thought id didn't work in Netscape 4. I wonder what else it doesn't
work in?

--
http://www.ericlindsay.com
Nov 23 '05 #24
On Tue, 15 Nov 2005 02:57:12 +0100, Eric Lindsay
<NO**********@ericlindsay.com> wrote:
In article <ta********************************@dtext.news.tel e.dk>,
Knud Gert Ellentoft <el*******@mail.tele.invalid> wrote:
Fred Lock skrev:
>> <h2><a name="vindaloo"></a>Vindaloo</h2>
>
>I figured this works too, but I guess it isn't valid or something.


Use id instead.

<h2 id="vindaloo">Vindaloo</h2>


I thought id didn't work in Netscape 4. I wonder what else it doesn't
work in?


MSIE 2.0 and lower. Opera 3.2 and lower. And probably in lots of other
browsers released before 1996...

--
Get Opera 8 now! Speed, Security and Simplicity.
http://my.opera.com/Rijk/affiliate/

Rijk van Geijtenbeek
Nov 23 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ad.von.reeken | last post by:
Hello CSS-ers, My question is: Is it possible to use CSS to prevent the 'Gecko-underline' behind 'anchored' images on pages with patterned background images? The page...
0
by: karlodb | last post by:
Hi all, I've been struggling with some strange VB behaviour for the last two days. I have created a usercontrol and placed two buttons in it. One is anchored bottom and right. When place the...
15
by: Robert Mark Bram | last post by:
Hi All! Problem I began with: Netscape/Opera supports hover for different elements, IE only supports hover for <a> and I want to use hover for <td class="menu"> I then found a fix using some...
5
by: Ben Sharvy | last post by:
I know I could do it by restricting hover to a class of links (a:hover.actuallyalink) but is there a way that doesn't require me to change every link in every existing html document?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.