javascript, css, z-index, div stacking

28,451

So, I got it. I set an absolute positioning on phantom_back and instead of trying to restack them I just set the visibility. When I tried to set the z-index it would fall apart on me.

<html>
<head>
    <script type="text/javascript">
    <!--//
        function phantom_back(image)
            {
                document.getElementById('phantom_back').style.height = 700;
                document.getElementById('phantom_back').style.width = 700;
                document.getElementById('phantom_back').style.zIndex = 50;
                phantom_top();
            }

        function phantom_top()
            {
                document.getElementById('phantom_top').style.height = 600;
                document.getElementById('phantom_top').style.width = 600;
                document.getElementById('phantom_top').style.visibility = "visible";
            }
    //-->
    </script>
</head>
<body>
    <a href="#" onclick="phantom_back()">Change</a>

    <div style="height: 700px; width: 700px; border: 2px black solid; margin:0 auto; background-color: red;" id="overlord">
        <div style="height: 10px; width: 10px; position: absolute; z-index: -1; background-color: #000000; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5;" id="phantom_back"></div>

        <div style="margin: 0 auto; text-align: center; height: 10px; width: 10px;  position: relative; z-index: 102; top: 10px; background-color: white; visibility: hidden;" id="phantom_top"><br /><br /><img src="load.gif"></div>
    </div>

</body>
</html>
Share:
28,451
aggitan
Author by

aggitan

I'm not very smart and I don't know very much.

Updated on July 02, 2020

Comments

  • aggitan
    aggitan almost 4 years

    I want to create a sort of light/thick box that only acts on a single DIV within a page. When mine fires off the first div(phantom_back) acts as I want it but the second, phantom_top sets its self after phantom_back regardless of its z-index and positioning.

    What am I doing wrong?

    Here is what I have so far:

    <html>
    <head>
        <script type="text/javascript">
        <!--//
            function phantom_back(image)
            {
                document.getElementById('phantom_back').style.zIndex = 100;
                document.getElementById('phantom_back').style.height = '100%';
                document.getElementById('phantom_back').style.width = '100%';
                phantom_top();
            }
    
            function phantom_top(image)
            {
                document.getElementById('phantom_top').style.zIndex = 102;
                document.getElementById('phantom_top').style.height = 600;
                document.getElementById('phantom_top').style.width = 600;
                document.getElementById('phantom_top').style.top = 0;
                document.getElementById('phantom_top').style.left = 0;
            }
        //-->
        </script>
    </head>
    <body>
        <a href="#" onclick="phantom_back()">Change</a>
    
        <div style="height: 700px; width: 700px; border: 2px black solid; margin:0 auto; background-color: red;" id="overlord">
            <div style="height: 10px; width: 10px; position: relative; z-index: -1; background-color: #000000; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5;" id="phantom_back"></div>
    
            <div style="height: 10px; width: 10px; position: relative; z-index: -3; margin: 0 auto; background-color: green;" id="phantom_top">asdf</div>
        </div>
    
    </body>
    </html>
    

    I was wandering why none of the tutorials I've been able to find offer something like this.