|
#1
|
|||
|
|||
|
I want the links only in a div called "header" to change the background and text colour on mouseover.
This is my coding in my CSS: Code:
#header a:link {color: #e76931; text-decoration: none;} /* unvisited link */
#header a:visited {color: black;} /* visited link */
#header a:hover {color: white;
background-color:#e76931; text-decoration: underline;} /* mouse over link */
#header a:active {color: #e76931; text-decoration: underline;}
h1 { font-family: Tahoma, Verdana, sans-serif;
color: #e76931 ;
font-weight:heavy;
font-size: 12px;
padding:5px 0px 0px 0px;
text-align:right;
line-height:14px;
margin:0px;}
HTML Code:
<a id="header" href="page.htm" alt="Link to page.htm"><h1>SOME TEXT</h1></a> In IE, the link goes orange (#e76931 ) but you can't see the white text. I'm sure I'm missing something really obvious, but I haven't done this sort of thing for ages. Do I have to JScript it? Thanx stax as always. WIWAG
|
|
#2
|
||||
|
||||
|
Well, you have too much going on, active and hover are at odds with each other, the order of the anchor styles is nonstandard, class is superior to id in this kind of situation, the h1 tag is in the wrong place. Alot of that can be fixed. I think I touched all the bases available with this demo:
HTML Code:
<html> <head> <title>CSS Trial</title> <style type="text/css"> a.header:link {color: #e76931; text-decoration: none;} /* unvisited link */ a.header:active {color: #e76931; text-decoration: underline;} a.header:visited {color: black;} /* visited link */ a.header:hover {color: white; background-color:#e76931; text-decoration: underline;} /* mouse over link */ h1 { font-family: Tahoma, Verdana, sans-serif; color: #e76931 ; font-weight:heavy; font-size: 12px; padding:5px 0px 0px 0px; text-align:right; line-height:14px; margin:0px;} </style> </head> <body bgcolor="gold"> <h1><a class="header" href="page.htm" alt="Link to page.htm">SOME TEXT</a></h1> </body> </html>
__________________
WWWWWWWWWWWW - John________________________ Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate |
|
#3
|
|||
|
|||
(sorry I'm one of those people that likes to know why.) As always thank-you very muchly for your answer. WIWAG
|
|
#4
|
||||
|
||||
|
I'm generally much bigger on what works than on why but, I'll give it a crack.
Active is roughly equivalent to onmouseDown and encompasses the moments from when the mouse is 'down' on the element until some other significant event takes place. Significant events will vary, I think, depending upon the rest of the page's construction but, generally include mouse up, mouse out and page unload events. Hover is more like onmouseOver and ends onmouseOut and on page unload. Making them the same isn't such a bad idea but, the browser will decide for you, usually favoring hover which should always follow the other pseudo classes in the declarations. I put h1 outside the anchor tag because if inside yes, it did override the anchor style. Generally, the style of the immediate element prevails, though there is such a thing as inheritance but, that usually occurs only when it is the default setting for a style and there is no other style for that property set for the contained element. Class versus id. You got me there, id didn't work. I think it may have to do with the fact that id (though widely abused in this fashion wherever browsers will support it) is supposed to be unique to a single element of a single type (ex: one anchor tag on the page), while class can be applied not only to several elements of the same type but also to any element on a page that supports the properties contained within the class definition. This begins to make more sense when you realize that by doing this: #header a:link you are creating the context for a unique anchor element that has the general pseudo class attributes you are about to assign to hover. It makes more sense to have: a:link #header but, I doubt that is any more valid to the browser. An effective way to use (some say, abuse) id's for these kinds of situations is to create two id's for an element and switch them onmouseOver and onmouseOut. ex: In the style section - Code:
#on {background:yellow;color:black}
#off {background:white;color:blue}
HTML Code:
<a id="off" href="some.htm" onmouseOver="this.id='on'" onmouseOut="this.id='off'">Click for Some Page</a>
__________________
WWWWWWWWWWWW - John________________________ Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate |
|
#5
|
||||||
|
||||||
|
Generally you CSS is fine. It is your markup that is the problem: it doesn't match the structure your selectors specify.
Quote:
![]() Quote:
Quote:
Quote:
Quote:
By the way, a h1 element is block-level, whilst an a element is inline. They cannot nest in the way you've presented above. Quote:
As I said, the problem was with the markup structure, not the CSS. If the markup is actually correct (that is, the a element really is supposed to have the header id attribute value), then change the selectors to #header:link, etc. Mike |
|
#6
|
|||
|
|||
|
Sweet, thanx for your time guys.
WIWAG |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|