Empty div hover event not firing in IE

陌路散爱 提交于 2019-11-28 18:23:01

it will work if you set a background-color or a border ...

if you could match either of these with the existing look then you would be ok..

(a background-image seems like the most unobtrusive solution)

Germs

None of comments and filters stuff works for me. The div is never rendered, so no hover possible.

Ultimate solution:

.aDiv {
    background: transparent url(../images/transparent.gif) repeat;
}

With a one pixel transparent gif image. Sure it works !

I know that the question has been answered but I encountered the same problem. The empty div wouldn't fire the function. And if it had a border only the border itself would start the function. I tried lots of stuff, nothing helped. Here is my solution, it's pretty much the same only thing is that I didn't use an image. Add this to your CSS:

div {             /* write the element's name, class or id here */
background: #FFF; /* you can choose any colour you like, 1.0-fully visible */
opacity:0.0;      /* opacity setting for all browsers except IE */
filter: alpha(opacity = 0); /* opacity setting for IE, 0-transparent & 100-fully visible */
}

If you want to preserve your DIV this worked for me: background-color: rgba(0,0,0,0.001);

@Skateball: that solution works, but also hides any child elements in FF/chrome. Here is my take:

background:#000;
background:rgba(0,0,0,0);
filter:alpha(opacity=0);
Mike Sherov

It's kind of hacky, and I don't know if it'll change the layout, but you could always just put an   inside the div.

Just insert an empty comment inside the "empty" element. :)

<div><!-- --></div>

This'll force IE to render the element

It might be that the hasLayout flag of the element needs to be forced. This can be done by applying the CSS property zoom:1 to it.

.trasnparentIE
{
    background: url(../images/largeTransparent.gif) repeat;
}

when I added the border the hover event only fired when the mouse was over or very close to the border but i dont need the border so i just use of transparent background and it works for me ... the transparent background did the trick for me (comments and nbsp didn't work either...)

You just can set opacity to make layer invisible and you should also set background

{
    background: white;
    opacity: 0;
}

I found the best way to float a mouse event tracking div over an area is to make the div 1px width and what ever height you need. Then give the div a transparent border-right of the actual width you need. The reason this works better than a transparent image is because if you use an image you then cannot track mousemove events, for example to drag, without the div losing focus (you instead will drag the image). I had this issue when both a jQuery UI slider or a mouse drag were used to scrub an animation. Here is a simple version of how my code looked.

//container div to hold the animation images this part doesn't really matter to answer the question
<div style="position:absolute; left:0px; top:0px; width:200px; height:200px">
// a bunch of images stacked like one of those animation flip books you made when you were a kid
   <img id="image01" src="blah01.jpg" />
   <img id="image02" src="blah01.jpg" />
   <img id="image03" src="blah01.jpg" />
   // and so on
</div>
//
// now the div that tracks the mouse events this is what I am describing to answer the question
// it could certainly be used above nav items and would have less load time than an image
<div style="position:absolute; left:-1px; top:0px; width:1px; height:200px; border-right: solid 200px transparent; />

In my application for every 2 px the mouse moved left or right I would give the appropriate image visibility while hiding all others and bingo you have an animation. (The empty div worked fine in all non IE browsers, but this worked in IE as well as non IE so no need to write it two ways.)

I was able to make use of the "Braille Pattern Blank" which is an invisible, non-whitespace character that is still "there", takes up a space, and allows events like mouseover to still fire. The snippet below shows this (the div isn't zero width as it would be if it were empty or contained only whitespace):

.notActuallyEmpty {
  background-color: gray;
  width:50px;
}
⠀⠀
<div class="notActuallyEmpty">⠀</div> <!--Unicode Character “⠀” (U+2800)--!>

If you don't have to support IE6. In your graphics program (Photoshop) create a 1x1 image of a white box. Reduce the opacity to 1%. Save as a PNG24 or GIF. Then, make this the background image for the transparent DIV.

This takes care of the issue and preserves the opacity of any child elements.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!