The functionality of my input and button tags is compromised because of the background animation

I'm facing an issue with the username and password input fields, as well as the login button. These elements are placed on a rectangle within an SVG tag.

The problem seems to be related to the animated background applied to one of the div elements in the body. While the animation runs smoothly, the input fields don't accept text input and the button doesn't respond to clicks. I attempted adjusting the z-index for the input fields and button without success, eventually removing them altogether.

The specific components causing trouble are identified by the IDs: loginButton, usernameInput, and passwordInput.

*{
    margin: 0;
    padding: 0;
}

.homePage-background{
    background: linear-gradient(to left, #8942a8, #ba382f);
    width: 100%;
    height: 100vh;
    z-index: 3;
}

.animation{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.animation li{
    position: absolute;
    display: block;
    list-style: none;
    width: 25px;
    height: 25px;
    background: rgba(255, 255, 255, 0.2);
    animation: animate 20s linear infinite;
    bottom: -150px;
}

.animation li:nth-child(1){
    left: 86%;
    width: 80px;
    height: 80px;
    animation-delay: -0s;
}

.animation li:nth-child(2){
    left: 12%;
    width: 30px;
    height: 30px;
    animation-delay: 1.5s;
    animation-duration: 10s;
}

.animation li:nth-child(3){
    left: 70%;
    width: 70px;
    height:70px;
    animation-delay: 4s; /*Change this to 5.5 seconds later and see the result*/
}

@keyframes animate{
    0%{
        transform: translateY(0) rotate(0deg);
        opacity: 1;
        z-index: 2;
    }
    100%{
        transform: translateY(-800px) rotate(360deg);
        opacity: 0;
        z-index: 2;
    }
}

#loginTitle{
    position: absolute;
    color: #dddddd;
    font-weight: bold;
}

#username{
    position: absolute;
    font-size: large;
    font-weight: bold;
    margin-top: 30%;
    margin-left: 20%;
    color: #dddddd;
}

#usernameInput{border-radius: 10px;}

#password{
    position: absolute;
    font-size: large;
    font-weight: bold;
    margin-top: 55%;
    margin-left: 20%;
    color: #dddddd;
}

#passwordInput{border-radius: 10px;}

#loginButton{
    position: relative;
    margin-left: 45%;
    margin-top: 65%;
    height: 40px;
    width: 70px;
    z-index: 0;
}

#loginButton:hover{
    background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="../css/homePage.css" type="text/css">
</head>

<body>
    <div class="homePage-background"> <!-- animation area-->
        <svg class="container-sm" width="400" height="760" style="position:absolute; margin-left: 35%; margin-top:35px">
            <rect id="loginRect" width="50%" height="100%" rx="40px" ry="40px" style="fill: cornflowerblue; stroke: pink; stroke-opacity: 0.0; stroke-width: 3px; "/>
            <foreignObject height="760" width="50%">

                <label id="username" for="usernameInput">UserName:
                    <input type="text" id="usernameInput" name="usernameInput" placeholder=" Enter your username ">
                </label>
                <label id="password" for="passwordInput">Password:
                    <input type="text" id="passwordInput" name="passwordInput" placeholder=" Enter your password">
                </label>
                <button type="submit" id='loginButton' value="Login" onclick="window.location.href='https://www.w3schools.com/tags/tag_button.asp';">Login</button>
            </foreignObject>
        </svg>

        <ul class="animation"> <!-- box area-->
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>

</body>
</html>

Any suggestions or assistance would be greatly appreciated. Thank you!

Answer №1

Was it needed? This is where the power of z-index comes into play. In the CSS code, a crucial edit was made.

*{
    margin: 0;
    padding: 0;
}


.homePage-background{
    background: linear-gradient(to left, #8942a8, #ba382f);
    width: 100%;
    height: 100vh;
    z-index: 3;
}

.animation{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.animation li{
    position: absolute;
    display: block;
    list-style: none;
    width: 25px;
    height: 25px;
    background: rgba(255, 255, 255, 0.2);
    animation: animate 20s linear infinite;
    bottom: -150px;
}

.animation li:nth-child(1){
    left: 86%;
    width: 80px;
    height: 80px;
    animation-delay: -0s;
}

.animation li:nth-child(2){
    left: 12%;
    width: 30px;
    height: 30px;
    animation-delay: 1.5s;
    animation-duration: 10s;
}

.animation li:nth-child(3){
    left: 70%;
    width: 70px;
    height:70px;
    animation-delay: 4s; /*Alter this to 5.5 seconds later and witness the effects*/
}

/*add this */
.container-sm {
    z-index: 9999;
}
/*---------------*/

@keyframes animate{
    0%{
        transform: translateY(0) rotate(0deg);
        opacity: 1;
        z-index: 2;
    }
    100%{
        transform: translateY(-800px) rotate(360deg);
        opacity: 0;
        z-index: 2;
    }
}

#loginTitle{
    position: absolute;
    color: #dddddd;
    font-weight: bold;
}



#username{
    position: absolute;
    font-size: large;
    font-weight: bold;
    margin-top: 30%;
    margin-left: 20%;
    color: #dddddd;
}

#usernameInput{border-radius: 10px;}

#password{
    position: absolute;
    font-size: large;
    font-weight: bold;
    margin-top: 55%;
    margin-left: 20%;
    color: #dddddd;
}

#passwordInput{border-radius: 10px;}

#loginButton{
    position: relative;
    margin-left: 45%;
    margin-top: 65%;
    height: 40px;
    width: 70px;
    z-index: 0;
}

#loginButton:hover{
    background-color: red;
}
<!DOCTYPE html>
<html lang="en>
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="../css/homePage.css" type="text/css">
</head>

<body>
    <div class="homePage-background"> <!-- animation area-->
        <svg class="container-sm" width="400" height="760" style="position: absolute; margin-left: 35%; margin-top:35px">
            <rect id="loginRect" width="50%" height="100%" rx="40px" ry="40px" style="fill: cornflowerblue; stroke: pink; stroke-opacity: 0.0; stroke-width: 3px; "/>
            <foreignObject height="760" width="50%">

                <label id="username" for="usernameInput">UserName:
                    <input type="text" id="usernameInput" name="usernameInput" placeholder=" Enter your username ">
                </label>
                <label id="password" for="passwordInput">Password:
                    <input type="text" id="passwordInput" name="passwordInput" placeholder=" Enter your password">
                </label>

                <button type="submit" id='loginButton' value="Login" onclick="window.location.href='https://www.w3schools.com/tags/tag_button.asp';">Login</button>
            </foreignObject>
        </svg>

        <ul class="animation"> <!-- box area-->
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>

</body>
</html>

Answer №2

You are currently utilizing an animation with a z-index: 3

To enhance the display, consider increasing the z-index value (4 or higher) within the container.

.container-sm {
  z-index: 4;
}

https://jsfiddle.net/MarkBurnsRed/37se02cr/7/

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

issue with excessive content overflow

I'm working with a div structure where the outer div has the following CSS properties: position: relative; overflow: hidden; min-heigth: 450px; Inside this outer div, there is another div with the following CSS properties: position: absolute; top: ...

adjust division size proportionally to another one

I am trying to create a layout with right and left divisions where the size of the left division matches the height of the browser window (100vh). The left division consists of two sub-divisions that need to have variable sizes but collectively match the ...

collapsed navbar issue in Bootstrap 4

The Navbar-toggle button was initially located on the top-right in both web and mobile modes. However, when the navbar collapsed in mobile mode, something went wrong (refer to the last image). I believe that the issue lies within the order of lines in my ...

Browse through the options in the dropdown list -Angular 6

I am looking to implement a filtering feature in my Angular app where data can be filtered based on the selected product number from a dropdown menu. The product data is structured in JSON format as shown below. component.ts productlistArray = [{ num ...

Accessing PHP parameters in JSP files can be accomplished by utilizing specific

The PHP code snippet below checks for a username and password match before redirecting to a JSP page. if($userName==$dbUserName&&md5($passWord)==$dbPassWord){ echo "<input name='username' type='hidden' value='$userN ...

Bootstrap's innovative design for a data grid

I'm currently working on designing a Grid using bootstrap 3. https://i.sstatic.net/DZzcq.png My tools include html5, css, and bootstrap integrated with React.js. The main feature of my project is a data grid (specifically, a Fixed Data Table). ...

Exploring the wonders of Bootstrap 3 panels and stylish floating images

Is it possible to create a responsive design using Bootstrap 3 panel along with a floating image positioned next to it? I want the panel to seamlessly fit into the available space, without overlapping the image. Can anyone provide guidance on achieving thi ...

What is the best way to center an embedded YouTube video using HTML5?

After experimenting with text align and center tags, I am still struggling. Can someone provide assistance? Appreciate it - Max ...

Determining the existence of a file on a different domain using JavaScript

One of the key tasks I need to achieve from JavaScript on my HTML page is checking for the existence of specific files: http://www.example.com/media/files/file1.mp3 // exists http://www.example.com/media/files/file2.mp3 // doesn't exist Keep in mi ...

Troubleshooting: Issues with jQuery's Class selector

Having trouble setting up an alert to trigger when a specific class anchor tag is clicked inside a div. This is what my HTML section looks like... <div id="foo"> <a class='bar' href='#'>Next</a> </div> And h ...

Different ways of manipulating images with JavaScript

I attempted to tackle the issue independently, but I'm stumped. Is there a way to adjust the width of an image in JS when the screen dimensions are changed? ...

Discover the concealed_elem annotations through the power of JavaScript

As I work on my new website, I am struggling with narrowing down the web code. I came across a solution that seems fitting for what I need, but unfortunately, I can't seem to make it work: I attempted the non-jQuery solution, however, I must be missi ...

Horizontal expanding and collapsing navigation menu

Is there a way to modify the expand menu bar so it expands from left to right or right to left, instead of top down? Any assistance would be greatly appreciated. Existing Expand Menu Bar <HTML> <HEAD> <META http-equiv="Content-Type" c ...

After submitting the form, the delete button in Bootstrap 4 has transformed into an unusual shape

I have a panel on my page, inside the panel header there is a red delete button. The panel content includes a form with several buttons (the red delete button is not inside the form, but linked to it with the form="abc" attribute). In the image below, whe ...

Tips for passing a timestamp to a Postgresql DB using a Button in a Form instead of a traditional rails time_select box

I am currently developing a CAD App in Rails 4 with Ruby 2. The goal is to provide users with a button on the screen to log an on-scene time and clear scene time, especially since most users will be using touch screen computers. Instead of using the defaul ...

Troubling inconsistency in jQuery's .css function performance

I'm facing a problem with the jquery .css function. I am using it to retrieve the actual height of elements that have their height set to auto. The code I am currently using is as follows: $(this).css({ height: $(this).css("height"), width: $(this).c ...

Using Javascript to Conceal Button for Unauthenticated Users

Our website is currently running on an outdated e-commerce CMS platform, which limits my options due to my beginner level skills in JavaScript and jQuery. One specific issue we are facing is the need to hide Prices and Add to Cart buttons for users who ar ...

Is it possible to access the HTML template prior to Outlook applying any additional classes during rendering?

I recently received an email template created in a different platform via Outlook. I am attempting to recreate this email in the Salesforce Marketing Cloud Platform, but I am encountering numerous unnecessary tables, classes set by Outlook (MsoNormal, Ms ...

Display a single image on the tablet and a distinct image on the computer

Currently, I am encountering an issue with my webpage located at . The problem lies in the right upper corner where a ribbon is located. However, when viewing the page on a tablet, the ribbon overlaps with my menu. To resolve this, I thought about displa ...

The Twitter card displays properly in the Twitter card validator, but does not appear on the Twitter feed

I am currently developing a project in C# webforms and incorporating Twitter cards to share the website's image and description. When I validate the card, it appears correctly but with a yellow warning indicating that "this card is redirected to the s ...