Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make element on top of everything

Tags:

html

jquery

css

I have a problem. I want my footer to be on top of everything else possible in my page. The trick is that I'm using Galleria plug-in and it has it's own style and for some reason even if I put z-index: 99999; on my footer it is still not on top.

This is galleria container, the main div of the plug-in.

.galleria-container {
    overflow: hidden;
    width: 960px; /* This value is changed by JS */
    height: 520px; /* This value is changed by JS */
    min-width: 960px;
}

This is my footer container

#footer
{
    z-index: 9999;
    width: 700px;
    height: 500px;
    position: absolute;
    background-color: aqua;
}

Okey so when I load my website it is fine and I can see my footer, but when I resize windows thus executing this code it is hidden again.

$(".galleria-container").css("width", $(window).width());
$(".galleria-container").css("height", $(window).height());
like image 910
Stan Avatar asked Jul 08 '11 18:07

Stan


People also ask

How do I make a div appear on top of everything else?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do I make a div in front of everything?

Use the CSS z-index property. Elements with a greater z-index value are positioned in front of elements with smaller z-index values. Note that for this to work, you also need to set a position style ( position:absolute , position:relative , or position:fixed ) on both/all of the elements you want to order.

How do I make a element take up the whole page?

If you set the width to 100% on the body element you will have a full page width. This is essentially equivalent to not setting a width value and allowing the default. If you want to use the body element as a smaller container and let the HTML element fill the page, you could set a max-width value on the body.


3 Answers

z-indicies are relative to other elements with a z-index in the same stacking context. Stacking context is defined by:

  • The Document Root
  • Elements with position: absolute or position: relative and a z-index
  • Elements that are partially transparent, that is they have an opacity < 1
  • In IE7, any element with position: absolute or position: relative (this can cause many bugs since it is the only browser that acts this way)

Put simply, whenever you have an element that matches any of the above, stacking context is reset and z-index is only relative to that container.

The simple answer to your question is one of two things:

  • raise the z-index even higher (some plugins use absurd z-index numbers)
  • make sure your footer is above the plugin in terms of stacking context. You may need to go up to parent nodes to set higher z-indicies or pull your footer out of a parent.
like image 140
Nobody Avatar answered Sep 18 '22 20:09

Nobody


Could try adding a z-index with !important on:

.galleria-container {
    overflow: hidden;
    width: 960px; /* This value is changed by JS */
    height: 520px; /* This value is changed by JS */
    min-width: 960px;
    z-index: 9998!important;
}
like image 41
Ant Avatar answered Sep 20 '22 20:09

Ant


Old topic, and old non-jQuery method, indeed. But a good approach to avoid being confused with arbitrary high z-index number is to set your object z-index to the highest index in the page + 1.

function topMost(htmlElement)
{
    var elements = document.getElementsByTagName("*");
    var highest_index = 0;

    for (var i = 0; i < elements.length - 1; i++) 
    {
        if (parseInt(elements[i].style.zIndex) > highest_index) 
        {        
            highest_index = parseInt(elements[i].style.zIndex);
        }
    }

    htmlElement.style.zIndex = highest_index + 1;
}

But having a fast jQuery method would be nice.

like image 34
Léon Pelletier Avatar answered Sep 21 '22 20:09

Léon Pelletier