View box 2 from the opposite side of box 1

I am looking for a way to make box2 appear behind box1.

One solution is to use position: relative; in the .box1 class.

However, this causes another issue in my project.

Is there a way to display .box2 behind .box1 without using position: relative; in .box1?

.main {
  height: 100%;  
}

#box1 {
  background: red;
  height: 200px;
  width: 100px;
  z-index: 999;
}

#box2 {
  position: relative;
  padding-top: 100px;
  padding-bottom: 79px;
  color: white;
  margin-top: -200px;
  margin-left: 110px;
  background: black;
  heigth: 200px;
  width: 100px;
  z-index: 1;
}

.animated {
  animation-duration: 1s;
  animation-fill-mode: both;
}

@keyframes slideInLeft {
  from {
    transform: translate3d(-100%, 0, 0);
    visibility: visible;
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}
.slideInLeft {
  animation-name: slideInLeft;
}
<div class="main">
<div id="box1">
</div>
<div id="box2" class="animated slideInLeft">
Some text 
</div>

</div>

Answer №1

Update the z-index value to -1

.container {
  width: 100%;
}

#elementA {
  background-color: blue;
  height: 150px;
  width: 75px;
  position: absolute;
  z-index: 10;
}

#elementB {
  position: relative;
  margin: auto;
  color: white;
  background-color: green;
  height: 150px;
  width: 75px;
  z-index: -1;
}

.animated-element {
 animation-duration: 2s;
 animation-fill-mode: both; 
}

@keyframes rotate{
 from {
 transform: rotate(0deg);
 }
 to {
 transform: rotate(360deg);
 }
}

.rotate-animation {
 animation-name: rotate;
}
<div class="container">
  <div id="elementA"></div>
  <div id="elementB" class="animated-element rotate-animation">
    Some content
  </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

Steps to insert a Drop-Down Sub-Menu

I'm just about finished with my navigation panel. Any tips on how to add a sub-menu? I currently have one in the Product page. Below is the HTML code containing the sub-menus: <nav> <ul> <li><a href="">HOME</a>&l ...

Troubleshooting problem with aligning grid items at the center in React using

I've been facing a challenge in centering my elements group using the material ui grid system. Problem: There seems to be excess margin space on the extreme right. Code snippet: const renderProjects = projects.map(project => ( <Grid item ...

The Sticky Navigation Bar Disappears After a Certain Scroll Point

Looking for some help with my website's navbar - it works fine until I scroll past the blue section, then it disappears along with other elements. Any suggestions on how to fix this? Thanks! <!DOCTYPE html> <html lang="en"> <h ...

Tips for updating images with HTML and CSS?

Sorry if this question seems strange, but I have a doubt that I need clarification on. Regarding assumptions: If I have 5 images, is it possible to change each image one by one (like a slider) using only HTML and CSS styles, without relying on jQuery or J ...

What is the method for displaying the word '<head>' within a <p> element in HTML code?

My HTML page contains a simple <p> tag. Within this tag, I am attempting to display some text in the following manner: Insert this code snippet into the website header, between <head> and </head>, to activate the functionality notice. ...

24-hour flatpickr timepicker

Can anyone assist me in setting my hour format to 24 hours instead of AM/PM in Angular? I've been struggling with it for the past 2 days. Below are my TypeScript and HTML code snippets: TypeScript: flatpickrOptions: any = { locale: French, enable ...

Difficulty viewing image in Firefox using HTML <img> tag

I'm encountering an issue with rendering an img tag in an HTML page. The img source is a file located on a remote server. Surprisingly, when attempting to display the image in Firefox using: file://///server/folder1/folder2/name.jpg it shows up prop ...

What methods can a web server or website use to trigger the re-caching of its own content?

We have recently launched a simple HTML and JS website that requires frequent updates to be reflected to users quickly. However, we are facing challenges with users having to clear their caches. We are exploring options within the HTML file or the Apache w ...

Sharing information through a hyperlink to a Bootstrap popup window

I've been attempting to send data to a Bootstrap modal window with no success so far. First, I tried: <a href="#TestModal?data=testdata" role="button" class="btn" data-toggle="modal">Test</a> However, the modal did not open as expected. ...

Error message: "Angular.js encountered a typeError stating that V2.example is not a function"

Having recently started learning Angular.js, I came across a tutorial that was created about a year ago. In this tutorial, I am attempting to implement a search feature that takes user input and searches for it on Github.com. Below is the HTML code snippet ...

Challenges encountered while constructing a flexbox layout

I have a flexbox design that I am trying to create with the specific layout shown in the image: https://i.sstatic.net/Sy20K.jpg My HTML code is as follows (and I do not want to make any changes to it): <div class="wrapper"> <div class="page-h ...

Acquiring HTML form information in ASP.NET controller

Currently, I have a view that includes an HTML login form and I am working on passing the form values to a controller via post. My goal is to display the user's username using the Content method once the form is submitted. However, I am facing an issu ...

Tips for successfully sending data to an ng-include controller

So, I've got this ng-include html element, and I'm trying to figure out how to pass data from an external source to the controller. The primary controller is responsible for fetching json data from a http webservice, and then parsing that data i ...

The status of the xmlhttp object remains unchanged

I was attempting to create an application showcasing the use of AJAX. Being new to AJAX, I couldn't pinpoint the error in my code. The XMLHttpRequest object is being created, but nothing else seems to be working. The ready state doesn't change to ...

Ways to enable smooth scrolling feature in Safari

I attempted to implement smoothscroll using a polyfill by adding the following code to the bottom of my body tag: <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e99a8486869d819a8a9b868585c ...

Bulk uploading HTML and CSS files to Squarespace made simple

Hello amazing people of the Stack Overflow community, I'm still learning the ropes around here (so please go easy on me) and I have a question about uploading HTML/CSS + Packages in bulk to my website. I have some experience with the code injection/ ...

Tips for dynamically adjusting an iframe's content size as the browser window is resized

Currently, I am in the process of building a website that will showcase a location on a map (not Google Maps). To achieve this, I have utilized an iframe to contain the map and my goal is for the map to adjust its width based on the width of the browser wi ...

Is TinyMCE creating unexpected <g> tags?

When I save content in the TinyMCE WYSIWYG editor, I notice that the HTML tag below keeps appearing throughout the text: <g class="gr_ gr_283 gr-alert gr_spell gr_run_anim gr_inline_cards ContextualSpelling ins-del multiReplace" id="283" data-gr-id="28 ...

Enhancing the appearance of jQuery datatables using Material Design Lite theme

I came across a helpful codepen demo demonstrating how to create a responsive data table with search filter and pagination. However, this demo is only integrated with Bootstrap. After searching the MDL discussion forum, I couldn't find any existing im ...

Restrict allowable dates according to user preference

In my Leave request form, employees can request various types of leaves such as paid leave, unpaid leave, and leave for blood donation. These types are stored in a Mysql table and displayed in a dropdown using the following code: <div class="form-g ...