Background Image in a Div (HTML web development)

Before elaborating on my issue, I'd like to clarify what I'm working on. I am developing a website where users are in a simulated "elevator". Upon pressing any of the 6 elevator buttons, the doors open and display information in the blank space. However, when attempting to input content into this space, the divs "rightdoor" and "leftdoor" shift downwards, causing the information to remain ontop....

My queries are: How can I prevent the div from shifting down? And how can I position one div behind another?

@-webkit-keyframes leftdooropen {
  from {
    right: 0%;
  }

  to {
    right: 50%;
  }
}

@-webkit-keyframes rightdooropen {
  from {
    left: 50%;
  }

  to {
    left: 100%;
  }
}

@-webkit-keyframes leftdoorclose {
  from {
    right: 50%;
  }

  to {
    right: 0%;
  }
}

@-webkit-keyframes rightdoorclose {
  from {
    left: 100%;
  }

  to {
    left: 50%;
  }
}

body, html {
  height: 100%;
  margin: 0;
}

#leftdoor {
  background-image: url("Door.png");
  position: relative;
    /* Full height */
  height: 100%;
  width: 50%;
    /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

#rightdoor {
  position: relative;
  left: 50%;
  background-image: url("Door.png");
  height: 100%;
  width: 50%;
  bottom: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  vertical-align: top;
}

.lframe {
  position: relative;
  height: 100%;
  width: 10px;
  left: 100%;
  z-index: 1;
}

.rframe {
  position: relative;
  height: 100%;
  width: 10px;
  right: 0%;
  z-index: 2;
}

.myButton {
  background: #3498db;
  background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
  background-image: -moz-linear-gradient(top, #3498db, #2980b9);
  background-image: -ms-linear-gradient(top, #3498db, #2980b9);
  background-image: -o-linear-gradient(top, #3498db, #2980b9);
  background-image: linear-gradient(to bottom, #3498db, #2980b9);
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  font-family: Arial;
  color: #ffffff;
  font-size: 20px;
  padding: 10px 20px 10px 20px;
  text-decoration: none;
}

.myButton:hover {
  background: #3cb0fd;
  background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
  background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
  text-decoration: none;
}

#celevator {
  z-index: -2;
  position: relative;
}

#1 {
  position: relative;
  bottom: 1000px;
}
<html>
<link rel="stylesheet" href="Design.css">

<head>

</head>

<body>

    <div id="leftdoor">
        <img class="lframe" src="frame.png">
    </div>

    <div id="1">

    </div>
    <div id="rightdoor">

        <img class="rframe" src="frame.png">

        <button class="myButton" style="position:relative; left:80%; bottom:75%;" onclick="openelevator(this)">1</button>
        <a href="#" class="myButton" style="position:relative; left:71.9%; bottom:68%;" onclick="openelevator(this)">2</a>
        <a href="#" class="myButton" style="position:relative; left:63.8%; bottom:61%;" onclick="openelevator(this)">3</a>
        <a href="#" class="myButton" style="position:relative; left:55.9%; bottom:54%;" onclick="openelevator(this)">4</a>
        <a href="#" class="myButton" style="position:relative; left:48%; bottom:47%;" onclick="openelevator(this)">5</a>
        <a href="#" class="myButton" style="position:relative; left:38%; bottom:35%;" onclick="openelevator(this)">Earth</a>
        <a href="#" class="myButton" style="position:relative; left:25%; bottom:27%;" onclick="openelevator(this)">> | <</a>

    </div>
</body>

Answer №1

Regarding your inquiry about how to prevent a div from moving down, I would recommend providing a functional example for better clarification.

As for your second question on how to position a div behind another div, are you looking for something similar to this?

.wrapper{
  border: 1px solid #aaa;
  width: 300px;
  height: 350px;
  background: #f0f0f0;
}
.div-1, .div-2{
  width: 150px;
  height: 200px;
  background: #6699cc;
  position: absolute;
  left: 30px;
  top: 30px;
}
.div-2{
  left: 60px;
  top: 60px;
  background: #cc9966;
}
<div class="wrapper">
  <div class="div-1">
    Div 1
  </div>
  <div class="div-2">
    Div 2
  </div>
</div>

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

The style attribute is triggering an error stating that 'Every child in a list must possess a distinct "key" property.'

Can anyone explain why I'm encountering an error when storing JSX code in a variable like this? const centerStyle = {textAlign: 'center'}; viewState.myContent = ( <Fragment> <p style={centerStyle}>Some text</p> < ...

Leveraging jQuery event listeners within a Javascript class initialization

Recently delving into OOP in JavaScript, I've been revamping some of my old code to make it more reusable. Instead of leaving them as inline scripts, I decided to encapsulate them within JavaScript classes. Here is an example of one of my classes: ...

What is the process for implementing filtered HTML attributes in a directive?

I’ve created a custom directive that generates a popup menu by extracting data from HTML content. The purpose is to transform a group of Bootstrap carousel-compatible elements into a structured list. However, each .item element contains an attribute with ...

"Adding an Image within a Textbox Using Ext JS: A Step-by-Step

How can I add a search image inside a textbox created with the following code? I have created a table with a footer, and within one of the textboxes in the table, I want to include a search button that will call another function when clicked. However, desp ...

Problem with Node.js Sequelize ORM model

Experiencing an issue with my web application using Sequelize, the Node.js ORM. When starting the Node server, I encounter the following error: Error: project_directory_path\node_modules\sequelize\lib\sequelize.js:322 model.init(attr ...

Is it possible to eliminate the dropdown (select) button from the dropdown menu?

Is there a method to eliminate the dropdown button (the small arrow) from the dropdown menu? I am looking to design an item list without the arrow. Steve ...

Calculate the total of array elements by using recursion, even if they are strings

Need to create a function that will return the sum of all elements in an array, but if the array contains strings like ["a","b","c"] // output : abc Currently, I have this code: function calculateSumRecursion(array) { ...

Ways to restart character count to zero if textarea is blank using jQuery

Can someone assist me with resetting the character count to zero when the textarea field is empty in jQuery? Currently, I have implemented code that successfully adds the character count as shown below; $(document).ready(function() { $('#content& ...

What is the best way to choose a span that contains a particular text?

Can you help me with changing the style of a span element? I have experience using JQuery to do this task. $("span:contains('OVERVIEW')").text("OVERVIEW "+ localStorage.getItem("shape")); I am looking for an Angular solution for the same probl ...

Insufficient height of Bootstrap jumbotron

I'm currently in the process of constructing a website using bootstrap. Here's my HTML file: Check it out here <header class="navbar navbar-inverse navbar-static-top" role="banner"> <div class="container"> <div cla ...

Activating event with mouse click or keyboard shortcut

I have a function that displays a form dialog with JqGrid when a link is clicked. This is how my code looks: HTML: <div id="mainDialog"> <a href='#' class='showList'>Show list [Ctrl+L]</a> .... </div& ...

CSS3 Animation: Facing issue with forwards fill behavior in Safari when using position and display properties

After creating a CSS3 animation to fade out an element by adjusting its opacity from 1 to 0 and changing the position to absolute and display to none in the last frames, I encountered an issue. In Safari, only the opacity is maintained while the position a ...

Is there a way to target a sibling element of another element by using its identifier in Cypress?

My current task involves clicking a checkbox within a list of table rows. The only way I can think of reaching this level is by targeting the span tag along with its corresponding name. cy.get('tr > td > span').contains('newCypressTes ...

Having trouble with submitting the jQuery form

I have written a script to submit a form after validation and receive the values in a PHP file using $_POST. However, I am not able to retrieve the values in the PHP file. When I try to echo the values, it shows up as blank. Can someone please guide me a ...

How can I find the week of the month using Moment.js? (similar to Google Calendar)

Currently leveraging the fantastic features of Moment.js, I am facing a dilemma. How can I determine which week of the month a particular date falls into? The documentation for Moment js only seems to provide information on "week of year." For instance, if ...

Are there JavaScript counterparts to the constant strings in Python?

In my search for a Javascript equivalent to the constant string ascii_lowercase 'abcdefghijklmnopqrstuvwxyz', I have come up empty-handed. However, I am more than willing to create it myself. Having found this feature useful in Python, I am curi ...

Obtain cell values while editing in JqGrid

I am utilizing JqGrid for data entry. Initially, an empty jqgrid is displayed upon page load. When a button is clicked, an empty row is added from the client-side only. Upon clicking the empty row, it becomes editable and allows for the addition of new v ...

Waiting for the asynchronous fetch operation to finish in a webpacked application block

Currently, I am facing an issue where I need to block the fetching of an external JSON file so that a configuration object can be consumed elsewhere. This process involves three files: builder.jsx runtime.jsx and a JSON file: config.settings.json In t ...

Bullet-point Progress Indicator in Bootstrap

Seeking guidance on how to create a Bootstrap progress bar with dots incorporated, similar to the image linked below. Any tips or resources where I can learn more about this technique? https://i.stack.imgur.com/BF8RH.jpg .progress { width: 278px; he ...

Techniques for extracting batches of n records from a database cursor (collection)

I am on a quest to showcase groups of 3 documents from my "Questions" collection, which contains about 50 documents. The plan is to display the first set of 3 questions in the template and then provide the users with an option (by clicking a button) to eit ...