/    Sign up×
Community /Pin to ProfileBookmark

Hmm… Pure CSS roll-overs?

Is it possible to have a totaly css roll-over, by this I mean when you move a mouse over it it changes colour.

If anyone can post a code / demonstration it would be most helpful ?

Cheers,

RyanJ

to post a comment
CSS

15 Comments(s)

Copy linkTweet thisAlerts:
@Daniel_TNov 11.2004 — There's the way that works on all elements, however it doesn't work in IE. Currently, the only way a CSS rollover will work in IE is if it's in an anchor.div#box {
background-color: #39c;
border: 1px solid #000;
width: 300px;
height: 300px;
position: absolute;
margin: -150px 0 0 -150px;
}
div#box:hover {
background-color: #09f;
border-color: #069;
}
div#box a {
color: #000;
text-decoration: underline;
}
div#box a:hover {
color: #fff;
text-decoration: none;
}

<div id="box">If you hover over this box in Firefox, the background and border will change color. If you hover over <a href="#">this link</a> in any browser, the color will change and the underline will disappear.</div>
Copy linkTweet thisAlerts:
@sciguyryanauthorNov 11.2004 — Cheers Dan ?

Very helpful, thanks.



RyanJ
Copy linkTweet thisAlerts:
@gotjesusyoNov 11.2004 — This code is used in the sucker fish drop down menu. It has a very...very small bit of java script that goes in the head section of the page...here is the code

<i>
</i>sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i&lt;sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


Then you would apply it to the object in css that you want to apply the hover command to.

The following would allow the list it to change color when it was hovered over.

This is how you would normally do it if IE worked correctly
<i>
</i>#nav li:hover {color: #000000}


But since IE is broke add this
<i>
</i>#nav li:hover, #nav li.sfhover { color: #000000}


You can add this ".sfhover" to anything that supports the hover command in css2 but does not work in IE.

While its not total css, it is a whole lot smaller then normal.
Copy linkTweet thisAlerts:
@David_HarrisonNov 11.2004 — Pure CSS (IE compatible) image rollovers:

[upl-file uuid=c8b05446-bdf6-4d8e-8a48-f3781bebf7de size=19kB]css_image_rollover.zip[/upl-file]
Copy linkTweet thisAlerts:
@sciguyryanauthorNov 11.2004 — Cheers all, I'll try each and see which is best (Or use all XD)


Thanks again,


RyanJ
Copy linkTweet thisAlerts:
@pawkyNov 13.2004 — [i]Originally posted by Daniel T [/i]

[B]There's the way that works on all elements, however it doesn't work in IE. Currently, the only way a CSS rollover will work in IE is if it's in an anchor.div#box {
background-color: #39c;
border: 1px solid #000;
width: 300px;
height: 300px;
position: absolute;
margin: -150px 0 0 -150px;
}
div#box:hover {
background-color: #09f;
border-color: #069;
}
div#box a {
color: #000;
text-decoration: underline;
}
div#box a:hover {
color: #fff;
text-decoration: none;
}

&lt;div id="box"&gt;If you hover over this box in Firefox, the background and border will change color. If you hover over &lt;a href="#"&gt;this link&lt;/a&gt; in any browser, the color will change and the underline will disappear.&lt;/div&gt;
[/B][/QUOTE]


very true, but vladdy describes how it can be [URL=http://www.vladdy.net/Demos/iepseudoclassesfix.html]fixed[/URL] by adding a .htc file. This will then work in all the browsers that it did work in ignoring the .htc file and it will work in IE which will read the .htc file. It is very easy, small, and works GREAT ?
Copy linkTweet thisAlerts:
@Daniel_TNov 13.2004 — [i]Originally posted by pawky [/i]

[B]very true, but vladdy describes how it can be [URL=http://www.vladdy.net/Demos/iepseudoclassesfix.html]fixed[/URL] by adding a .htc file. This will then work in all the browsers that it did work in ignoring the .htc file and it will work in IE which will read the .htc file. It is very easy, small, and works GREAT ? [/B][/QUOTE]
Though, outrageously invalid unless you have access to a server-side language. If you have a server-side language, you can check for IE and import the behaviors stylesheet if the user is using IE.
Copy linkTweet thisAlerts:
@VladdyNov 13.2004 — [i]Originally posted by Daniel T [/i]

[B]Though, outrageously invalid unless you have access to a server-side language. If you have a server-side language, you can check for IE and import the behaviors stylesheet if the user is using IE. [/B][/QUOTE]

What is so outrageously invalid, huh?:rolleyes:

http://www.w3.org/TR/CSS21/syndata.html#parsing-errors
Copy linkTweet thisAlerts:
@pawkyNov 13.2004 — yea, i dont c how it isnt valid O_o
Copy linkTweet thisAlerts:
@Daniel_TNov 14.2004 — [i]Originally posted by Vladdy [/i]

[B]What is so outrageously invalid, huh?:rolleyes:

http://www.w3.org/TR/CSS21/syndata.html#parsing-errors [/B]
[/QUOTE]
Ahhh... nice ? Before, I had just been using the behavior in the CSS, without any of that other stuff, which gave an error ?
Copy linkTweet thisAlerts:
@Daniel_TNov 17.2004 — TIME OUT!

This method IS infact invalid. Vladdy, try validating the CSS on that article you wrote ?
Copy linkTweet thisAlerts:
@VladdyNov 17.2004 — Validator is not a Bible, but a tool that helps you make better web sites.

CSS that does not give you validation errors (notive that it is different from "valid CSS") is NOT a goal and actually most times is impossible when you try to keep the dumb IE happy.

What you need to do when running CSS through validator is to understand each error and warning and how it may affect your web site.
Copy linkTweet thisAlerts:
@AbhothNov 17.2004 — Validates html strict and happy css ... one small bg image and nothing else.

[URL=http://mywebpages.comcast.net/abhoth/seecrap/index.htm]Demo link...[/URL]
Copy linkTweet thisAlerts:
@David_HarrisonNov 18.2004 — [i]Originally posted by Abhoth [/i]

[B]Validates html strict and happy css ... one small bg image and nothing else.

[URL=http://mywebpages.comcast.net/abhoth/seecrap/index.htm]Demo link...[/URL][/B]
[/QUOTE]
That's because IE supports the :hover psuedo-class on anchor elements, just not on other elements.

And dude, do write for Star Trek or something? Check out [url=http://www.lipsum.com]lipsum.com[/url] for all your filler text needs. :p
Copy linkTweet thisAlerts:
@AbhothNov 18.2004 — Yeah, but I try not to dwell on what IE does, doesn't or should support... gives me a headache.
×

Success!

Help @sciguyryan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...