on hover background image

This is a discussion on on hover background image within the CSS forums, part of the Development category; i am using the following code to show a background image when the mouse moves on a div <div class="logobg"> ...


Reply
 
LinkBack Thread Tools Display Modes
Old 2nd March 2010, 08:58 AM   #1
Member
 
Join Date: Sep 2009
Posts: 169
Thanks: 0
Thanked 0 Times in 0 Posts
sudhakararaog is on a distinguished road
Expertise: Total Beginner
Experience: Basic / None
Default on hover background image

i am using the following code to show a background image when the mouse moves on a div

<div class="logobg">
</div><!-- logobg ends -->

.logobg{
float: left;
width: 736px;
height: 384px;
background: url(logo.jpg) no-repeat 0px 0px;
}

.logobg:hover{
float: left;
width: 736px;
height: 384px;
background: url(logorollover.jpg) no-repeat 0px 0px;
}

this is working fine in all browsers except for ie6 in ie 6 when i move the mouse over the logogb div the logorollover.jpg does not appear

i have tried the following

<div class="logobg">
<!--[if IE 6 ]>
<div id="logo">
<img src="assets/img/logo.jpg" id="logoie" onmouseover="over()" onmouseout="out()">
</div>
<![endif]-->
</div><!-- logobg ends -->

function over(){
document.getElementById("logoie").src="logorollove r.jpg";
}

function out(){
document.getElementById("logoie").src="logo.jpg";
}

also tried using

function over(){
var imgsrc=document.getElementById("logoie").getAttrib ute("src");
document.getElementById("logoie").setAttribute("sr c",
"logorollover.jpg");
}

function out(){
var imgsrc=document.getElementById("logoie").getAttrib ute("src");
document.getElementById("logoie").setAttribute("sr c", "logo.jpg");
}

the image is not changing in ie6

please advice thanks
sudhakararaog is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 2nd March 2010, 10:08 AM   #2
admin
 
Frinkky's Avatar
 
Join Date: Dec 2008
Posts: 700
Thanks: 0
Thanked 37 Times in 37 Posts
Frinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond repute
Expertise: Design & Graphics
Experience: Professional
Default

ie6 only acknowledges the :hover pseudo class on <a> tags. You could replace the div with an a tag, and style in css to behave like a div (display: block, margin, padding, width, height etc etc).
__________________
Jon Warner
Web Pro Cafe :: The PixelForge :: Follow my Twits (or something) :: LinkedIn
Frinkky is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 2nd March 2010, 10:20 AM   #3
Member
 
Join Date: Sep 2009
Posts: 169
Thanks: 0
Thanked 0 Times in 0 Posts
sudhakararaog is on a distinguished road
Expertise: Total Beginner
Experience: Basic / None
Default

thanks for replying i have tried the following

<div class="logobg">
<!--[if IE 6 ]>
<a class="logoie6">
<div id="logo">
<img src="assets/img/logo.jpg">
</div>
</a>
<![endif]-->

</div><!-- logobg ends -->


#logo{
float: left;
width: 736px;
height: 384px;
background: url(../assets/img/logo.jpg) no-repeat 0px 0px;
}
a.logoie6{
display:block;
width: 736px;
height: 384px;
}
a.logoie6:hover div {
background: url(../assets/img/logorollover.jpg) no-repeat 0px 0px;
}

the image does not appear on hover

can this be done using javascript on mouseover and onmouseout as i mentioned in the earlier post

thanks
sudhakararaog is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 2nd March 2010, 10:45 AM   #4
admin
 
Frinkky's Avatar
 
Join Date: Dec 2008
Posts: 700
Thanks: 0
Thanked 37 Times in 37 Posts
Frinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond reputeFrinkky has a reputation beyond repute
Expertise: Design & Graphics
Experience: Professional
Default

There's a bunch of stuff regarding whatever:hover here: Whatever:hover

I'd read it myself, but I have a headache after trying to ;) you'll see what I mean.
__________________
Jon Warner
Web Pro Cafe :: The PixelForge :: Follow my Twits (or something) :: LinkedIn
Frinkky is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 3rd March 2010, 05:40 PM   #5
moderator
 
kozata-xakep's Avatar
 
Join Date: Feb 2010
Location: Varna, Bulgaria
Posts: 50
Thanks: 0
Thanked 11 Times in 11 Posts
kozata-xakep will become famous soon enough
Expertise: Web Development
Experience: Professional
Default

I would advice you to use 'h1' for your logo and 'a'. SEO friendly and no problems.

Code:
<h1 id="logo"><a href="#">Site Name</a>
Code:
h1#logo { float: left; display: inline; height: 100px; width: 100px; }
h1#logo a { display: block; height: 100px; background: url(images/logo.gif); }
h1#logo a:hover { background: url(images/logo-hover.gif); }
Since your logo isn't PNG you can even do it with a sprite to reduce the HTTP Requests.
kozata-xakep is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Reply

Tags
background, hover, image

Thread Tools
Display Modes