Trouble with z-index when attempting to stack forms on top of one another

Currently, I am working on creating a login page and signup page for my program. The goal is to stack them on top of each other with only one being displayed at a time. However, I am facing an issue where they are not stacking properly. I attempted using the position: absolute method as suggested by someone, but it caused formatting issues across the entire website. I am also incorporating bootstrap classes into this project.

<div class="bg"></div>
<div class="bg bg2"></div>
<div class="bg bg3"></div>
<h1 class="burning_text">WELCOME!</h1>
<div id="main-menu" class="container-fluid">
    <div class="row">

        <div class="col"></div>

        <div class="col" id="outer_container">

            <div id="main_container">

                <form id="login_form" class="form-horizontal bg-secondary animate__animated" action="javascript:void(0);">
                    <div class="row">
                        <div class="row form-group" style="position:relative; left:10%;">
                            <label class="temporary control-label">Name:</label>
                            <input id="login_name_input" class="form-control" type = "text" required maxlength="40" placeholder="username">
                        </div>


                        <div class="row form-group" style="position: relative; left: 10%">
                                <label class="temporary control-label">Password:</label>
                                <input id="login_password_input" class="form-control" type = "password" required maxlength="40" placeholder="password">
                                <button id="login_alter_button" type="button" style="position: relative; bottom: 35%; left: 100%; height: 40px;"><i class="fas fa-eye-slash"></i></button>
                        </div>


                        <div class="row form-group">
                            <button class="btn btn-info" id="login_submit_button" style="margin: 40px; position: relative; top: 50%; right:130%;">login <i class="fas fa-door-open" style="font-size: 48px;"></i></button>
                        </div>

                        <div class="row">
                            <button class="btn btn-primary" id="switch_signup_button" type="button" style="position: relative; left: 207%; font-size: 15px; height: 30px;">switch to signup <i class="fas fa-sign-in-alt"></i></button>
                        </div>


                    </div>

                    
                </form>







                <form id="signup_form" class="form-horizontal bg-primary animate__animated" action="javascript:void(0);">
                    <div class="row">
                        <div class="row form-group" style="position:relative; left:10%;">
                            <label class="temporary control-label">Name:</label>
                            <input id="signup_name_input" class="form-control" type = "text" required maxlength="40" placeholder="username">
                        </div>


                        <div class="row form-group" style="position: relative; left: 7%">
                            <div class="col-10">
                                <label class="temporary control-label">Password:</label>
                                <input id="signup_password_input" class="form-control" type = "password" required maxlength="40" placeholder="password">
                            </div>
                            <div class="col-2">
                                <button id="signup_alter_button" type="button" style="position: relative; top: 45%; right: 90%; padding: 5px;"><i class="fas fa-eye-slash"></i></button>
                            </div>
                        </div>


                        <div class="row form-group">
                            <button class="btn btn-info" id="signup_submit_button" style="margin: 40px">signup <i class="fa fa-user-plus" style="font-size:48px;"></i></button>
                        </div>

                        <div class="row">
                            <button class="btn btn-secondary" id="switch_login_button" type="button" style="position: relative; left: 93%; top: 80%; font-size: 15px; height: 30px;">switch to login <i class="fas fa-user"></i></button>
                        </div>


                    </div>

                    
                </form>



            </div>


        </div>

        <div class="col"></div>

    </div>



</div>

The current issue is that they appear stacked in a block fashion due to the CSS classes:

#login_form
{
    left: 100%;
    font-size: large;
    font-family: Rockwell;
    display: block;
    
}

#signup_form
{
    font-size: large;
    font-family: Rockwell;
    display: block;
    position: relative;
    z-index: -1;
    bottom: 50%;
}

https://i.sstatic.net/xW6gY.jpg

Answer №1

Unfortunately, I don't have the entire CSS code available, but in my experience, they do stack properly. If this solution doesn't work for you, please don't hesitate to inform me.

Revised Edition

Another approach could be to utilize display: none; to hide the second form and toggle it back to display:block; using JavaScript when switching between forms, which seems like a viable solution.

Additionally, keep in mind that absolutely positioned elements are taken out of the document flow.

.main_container {
    position: relative;
}

#login_form {
    font-size: large;
    font-family: Rockwell;
    display: block;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
}

#signup_form {
    font-size: large;
    font-family: Rockwell;
    display: block;
    position: absolute;
    z-index: -1;
    width: 100%;
    left: 0;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Change the color of the Parent Menu when a childMenu is clicked on using CSS and HTML

<li class="btn-group" mdbDropdown> <a mdbDropdownToggle id="ParentId"> <i class="nav-item"></i> MainMenu <i class="fa fa-angle-down"></i> </a> <div class=" ...

Aligning two floating elements vertically in respect to each other

Although the topic of vertically centering elements is common on various websites, I am new to HTML and still find it confusing even after doing some research. I attempted to create a basic header element for a website that includes an h1 title and a navi ...

Can CSS actually generate accurate inches?

Can you accurately set the width of an element, like a div, in inches and expect it to maintain that width across different devices? Or will it simply scale at a ratio like 1in = 96px? Edit: Try using CSS to set an element's width in inches and then ...

What could be the reason behind this HTML table behaving responsively on a desktop view but not on a mobile view

My goal is to create an HTML table that will display the td's in a stacked, card-like form when viewed on mobile devices. While it works correctly on a narrow desktop screen, the problem arises when viewing it on mobile. I've realized that the ...

Make the inner div within the td stretch to cover the entire height of the td

Inside the first tds, there is dynamic text content that automatically expands the trs and tds. However, the second tds have a div with a background image but no text inside. I want these divs with background images to expand or collapse along with the tab ...

What methods should I employ to rectify this asymmetrical border?

Within my HTML and CSS table, I've noticed that the first column has a different height compared to the rest. It appears uneven with the columns on its right. Please execute the code snippet below. The specific block I'm referring to is labeled ...

Elements of the form located outside the form container

Here is my requirement: <form> input field <form> input field submit </form> input field input field <form> input field submit </form> submit </form> I am using trans ...

Struggling with Responsive Design Challenges with Grid Material UI?

Encountering an issue while using the Grid Component in my React JS Project. Let's delve into some code and then I'll explain what I aim to achieve with images: Assuming this is the rendered code: <div style="margin:100px 20%; width:80%" &g ...

HTML: Hover effect does not work for icons when hovered alongside anchor elements within a list item

I wanted to add a special effect to my navigation list items: When the mouse hovers over the anchor tags of the list items (or even in the active state), I wanted the image in the <span> to be replaced with a colored version of the image. The color o ...

Transparent CSS Table Styling

Can you create a CSS effect where all content inside a table becomes transparent on hover? For example: <table><tr><td> AN IMAGE </td> <td> SOME TEXT </td></tr></table> So if either the image or the text ar ...

Why does Bootstrap v4 distinguish between theme-color and standard color variables?

Bootstrap v4.0.0.beta.2 introduces color maps allowing the use of theme-color("primary") instead of $brand-primary. If I am adding my own custom CSS and want to utilize Bootstrap colors, what is the benefit of using the theme-color function over directly ...

"Enhance the styling with jQuery's css() function when clicked

I am currently working on the following code: $(document).ready(function(){ $("#FlatCheckbox").click(function(){ $("#style1").css("margin-top",10); }); }); <h2> <input type='checkbox' id="FlatCheckbox" class=" ...

Comparing the impact of mixins styles versus additional style rules

I have customized mixins for a red button. For example: .btnRed{ background:red; color:white; border-radius:3px; min-width:200px; font-size:18px; } I typically use this to style my main buttons, but for one specific button, I n ...

Unable to customize the button color within the Bootstrap framework

This button was created using Bootstrap. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <lin ...

What is the best way to adjust the font weight of a Bootstrap 4 modal header?

Is there a way to adjust the font weight in the header of a Bootstrap 4 modal? As an added challenge, I'm also interested in changing the font color to #7f7f7f... <div class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog" r ...

how can I incorporate PHP paths in my CSS?

I am attempting to assign a path to an image using a PHP variable in CSS, as demonstrated below: <?php $path= "www.ghhelpline.com/hello/images/" ?> <style> .hello { background-image: url("<?php echo $path;?>new.png") ...

Having trouble loading images in CodeIgniter? Even though your image path is correct, are you getting a

In my application, I store the image path in a database and have a method called Uploads: function uploads($path) { echo base_url('application/uploads/'.$path); return true; } //base url is $config['base_url'] = 'https ...

Retrieve the CSS attributes within a directive specifically designed for child elements

Currently, I am iterating through the child elements of the element to which the directive is attached, and adding mouseup and mousedown callbacks: var dragDroppables = element[0].children; for (var elementIdx = 0; elementIdx < dragDroppables. ...

Samsung devices exclusively showcase background in responsive design

I am encountering a major problem with my website design, specifically with its compatibility on mobile devices. To ensure its responsiveness, I have tested the design on my iPhone, iPad, and Windows Phone. Unfortunately, since I lack an Android device, I ...

Accordion-inspired multi-layer list navigation

I have been searching everywhere but haven't found a solution to this issue. My list menu has the following markup: <div id="menu"> <ul> <li>Category #1 <ul> <li>Item #1</li> <li>I ...