Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover on menu disappears when using background slider with position:fixed and z-index

I found out that the hover effect from the main menu disappears if I want to go to the second menu level. Here you find the example:

http://bfb.bplaced.net/ie/

HTML:

<div id="background-slider">
    <a href="http://www.hdwallpapersarena.com/wp-content/uploads/2012/10/Opera-Background-Blue-Swirls.jpg"></a>
    <a href="http://www.hdwallpapersarena.com/wp-content/uploads/2012/10/green-abstract-background.jpg"></a>
</div>
<div id="menu">
    <nav>
        <ul class="nav-level-1">
            <li class="level-1 clearfix">
                <a href="unternehmen.html" class="level-1">Unternehmen</a>
                <ul class="nav-level-2">
                    <li class="level-2"><a href="/unternehmen/die-firma.html" class="level-2">Die Firma</a></li>
                    <li class="level-2"><a href="/unternehmen/das-team.html" class="level-2">Das Team</a></li>
                    <li class="level-2"><a href="/unternehmen/allgemeines.html" class="level-2">Allgemeines</a></li>
                </ul>
            </li>
        </ul>
        <div class="clearer"></div>
    </nav>
</div>
<div id="script-section" class="hidden">
    <script src="./js/jquery.superbgimage.min.js"></script>
    <script>
        $(document).ready(function(){
            // Options for SuperBGImage
            $.fn.superbgimage.options = {
                transition: 1,
                speed: 'slow',
                randomtransition: 0,
                slideshow: 1,
                slide_interval: 6000,
                randomimage: 0
            };

            // initialize SuperBGImage
            $('#background-slider').superbgimage().hide;
        });
    </script>
</div>

CSS:

#menu {
    position: fixed;
    z-index: 4;
    left: 23px;
    bottom: 40px;
}

ul.nav-level-1 {
    float: left;
    text-align: left;
}

ul.nav-level-1 li.level-1 {
    /*float: left;*/
}

ul.nav-level-1 li.level-1 a.level-1 {
    font-family: 'SourceSansProBlack', Arial, sans-serif;
    font-size: 36px;
    line-height: 40px;
    text-transform: uppercase;
    text-decoration: none;
    color: #123373;
    padding: 0 5px;
    transition: color 0.25s ease 0s, background-color 0.25s ease 0s;
    float: left;
}

ul.nav-level-1 li.level-1 a.level-1:hover {
    text-decoration: none;
    color: #123373;
    background-color: #FFF;
    display: inline-block;
}

ul.nav-level-1 li:hover a {
    background-color: #FFF;
}

ul.nav-level-1 li.level-1:hover ul.nav-level-2 {
    display: block;
}

ul.nav-level-2 {
    display: none;
    float: left;
    width: 390px;
    padding-left: 10px;
    text-align: left;
}

ul.nav-level-2  li.level-2 {
    margin-bottom: 3px;
    margin-right: 5px;
    float: left;
}

ul.nav-level-2  li.level-2 a.level-2{
    font-family: 'SourceSansProBold', Arial, sans-serif;
    font-size: 14px;
    line-height: 16px;
    text-transform: uppercase;
    text-decoration: none;
    color: #123373;
    padding: 0 5px;
    background-color: #FFF;
    transition: color 0.25s ease 0s, background-color 0.25s ease 0s;
}

ul.nav-level-2  li.level-2 a.level-2:hover{
    background-color: #123373;
    color: #FFF;
}

The slider I'm using is called SuperBGImage. If I remove the slider everything works!

I thin it's the z-Index bug of IE but I tried different options by adding position: relative; without success. How do I get the hover effect fixed in IE?

I tried this JS code but it doesn't help either:

$('li.level-1').hover(function() {
    $(this).children('ul.nav-level-2').removeClass('hidden');
    $(this).children('ul.nav-level-2').addClass('visible');
});
$('ul.nav-level-2').mouseout(function() {
    $(this).removeClass('visible');
    $(this).addClass('hidden');
});

Perhaps it is a float issue. If I remove float: left; than it works better but it is not the design which it should be.

Edit:

Here you can download the project. I noticed another thing. If I start the Internet Explorer he asks me if I want to start the scripts or the Active-X elements. Why does he ask me that? I know it's because the slider but it should be normal Javascript. Perhaps the JS from the slider does something special here ...

like image 702
testing Avatar asked Apr 11 '13 09:04

testing


1 Answers

I've got it working on IE9 & IE10 should also work in IE8, using transparent background and hovering over .clearfix

Check out the updated - jsFiddle

I changed this-

ul.nav-level-1 li.level-1 a.level-1:hover {
    text-decoration: none;
    color: #123373;
    background-color: #FFF;
    display: inline-block;
}

To this-

.clearfix:hover ul.nav-level-1, li.level-1, a.level-1{
    text-decoration: none;
    color: #123373;
    background: rgba(0, 0, 0, 0.0); /*** TRANSPARENT BACKGROUND FIX ***/
    display: inline-block;
}

And added height and width to this-

.clearfix {
    display:block;
    width:100%;    /* added height and width */
    height:50px;
}

for IE7 and below add-

<!--[if lte IE 7]>
    <style type="text/css">
 .clearfix:hover ul.nav-level-1, li.level-1, a.level-1 {
    text-decoration: none;
    color: #123373;
    background:#ffffff;
    display: inline-block;
}
    </style>
<![endif]-->

The above work around just replaces the transparent rgba with a solid white. It wont be as pretty in ancient IE, but few things ever are.

Note, that <nav> isn't supported in IE8 and below

like image 56
apaul Avatar answered Oct 21 '22 09:10

apaul