How to make a block element overlap an element positioned absolutely

Can anyone help me achieve the following setup?

I have a scenario where I need one div to be positioned absolutely, and another div as a simple block element overlapping the absolute container. This image illustrates what I'm trying to accomplish:

The red box is the absolutely positioned element and the blue box is a standard block element (inside a flexbox).

https://i.sstatic.net/0IBmK.png

I've attempted using z-index to achieve this effect, but it hasn't been successful.

Thank you for any assistance.

Edit: For more context, here's a fiddle with my code:

https://jsfiddle.net/xzp284vn/

<div class="container">
  <div class="block">
  </div>
  <div class="absolute">
  </div>
</div>
.container {
  display: flex;
  justify-content: flex-end;
  position: relative;
  width: 400px;
  height: 300px;
}

.block {
  border: 1px solid blue;
     width: 40px;
  height: 300px;
}

.absolute {
  border: 1px solid red;
  position: absolute;
  top: 0;
  left: 0;
   width: 400px;
  height: 40px;
  background: yellow;
}


Answer №1

.red{
  height:100px;
  border: 1px solid red;
}
.blue{
  border: 1px solid blue;
  width: 150px;
  position: absolute;
  right:30px;
  top:9px;
  height:300px;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

  <div class="red">
  
  </div>
  <div class="blue">
    
  </div>
  
</body>
</html>

This is the solution you have been seeking.

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 speed at which Laravel loads local CSS and JS resources is notably sluggish

Experiencing slow loading times for local resources in my Laravel project has been a major issue. The files are unusually small and the cdn is much faster in comparison. Is there a way to resolve this problem? https://i.stack.imgur.com/y5gWF.jpg ...

Ways to specifically locate the initial list items

Need help creating an array of the first li elements but unsure of how to proceed. Here is the HTML structure: <div class="nav"> <ul> <li>Element 1</li> <li>Element 2 <ul> <li>Element ...

Hide the navigation menu when a page link is selected

Within my Angular 8 application, a fixed navigation bar is positioned at the top of the screen. Upon hovering over a dropdown nav link, a menu will appear for the user to explore. However, when a user clicks on one of these menu links, Angular Routing is ...

Ways to display dynamic information in a vertical list using HTML (MEAN stack)

I am receiving an array of data from the backend and looking for a way to display them in a vertical list using HTML. Can anyone help me with this? Below is my current code snippet. TS: this.sub = this.route.params.subscribe(params => { this.http.g ...

Triggering a targeted action upon the user's click on any HTML element

Currently, I am in the process of developing navigation buttons that trigger a dropdown sub-menu when clicked by utilizing checkbox inputs. Upon clicking the label, the input is checked, causing the menu to drop down, and when the label is clicked again, t ...

A couple of inquiries (Bounce, Align)

I am attempting to center the text within the circles and make them bounce when the circle is hovered (the text inside the circle). Check it out here: http://jsfiddle.net/cJ3se/ Would appreciate any assistance. Denver ...

Is it possible to implement a unique style exclusively for my application's components?

Recently, I've been trying to apply a universal style rule to my entire app similar to this: div { width: 100%; } At first, everything seemed to be working perfectly. However, when I began integrating third-party components that have their ow ...

How can I apply bold styling to primary nodes in jsTree using CSS?

I am currently utilizing the in conjunction with asp.net mvc. My objective is to apply bold styling to the text using CSS within the main nodes, specifically those with arrows (refer to the image below). https://i.sstatic.net/xg3uF.png Below is the code ...

Using Javascript to replace elements with input fields and text areas

I'm currently working on a unique project for my Wordpress blog, where I am developing a custom block editor using JavaScript on the frontend. The goal is to convert all elements from the post content into a series of inputs and textareas. To begin, ...

Tips for executing a jQuery nested template in a recursive manner

Imagine a world where JSON objects and jQuery templating collide in a thought-provoking inception-like scenario. How can we dive deeper into this rabbit hole? The catch is, I'm a bit lazy and hoping the code will do most of the heavy lifting... Q:& ...

Displaying items using the flex property can cause the top resize feature to be unreachable

My issue revolves around the display of input errors, which are causing the top section to become inaccessible. I am looking for a solution that will align the content both vertically and horizontally in the center. The challenge arises when the card conta ...

Show an image on a webpage using a URL from a Firebase database with HTML

How can I dynamically display images from URLs in my table? My table automatically increments every time new data is added, but I'm having trouble displaying images. The table already shows the URL where the image should be displayed. Here is the ou ...

Add a unique design to a list element with CSS

I've successfully arranged a simple list in a line with a background image for all items. However, I want to have a different background image for specific list items (List item 3) without resorting to using !important. Below is the code I am currentl ...

What is the accurate method of sending form data to the SQL database?

This is the data submission form I am using: <p align="center" style="color:#F00;"> <?php echo $msg; ?> </p> <form class="form-horizontal style-form" name="form1" method="post" action="Create-jobs.php" onSubmit="return validate(); ...

Creating a CSS class dynamically with AngularJS: A step-by-step guide

I'm working on an Angular JS website that pulls data from an API to create a dynamic CSS class. This class will be used to format other data being displayed on the page. Is there a way for Angular JS $scope data to be generated in the Controller whil ...

How to use AngularJS to collapse various panels with unique content

Hey everyone, I'm working on developing a collapsible panel using Angular. The panel should consist of a header and body to display the content. The desired behavior is that when a button is clicked, the content collapses down, and clicking the same b ...

Designing Post Archive with Flexbox to create dynamic layouts

I am currently exploring different techniques to style my columns, and I have encountered an issue where if there are less than 4 posts in a row, there is extra space between each post. While I understand that floats can resolve this problem, I am searchin ...

JavaScript Application - Problem with Universal Windows Script

I recently built a website utilizing material design lite for the aesthetics: Here are the scripts included: <script src="./mdl/material.min.js"></script> <script src="Scripts/angular.min.js"></script> The necessary .css fi ...

The issue with jQuery trigger not passing the value of a radio button has been

I have implemented a radio button (Yes, No) and an input text box on my form. If the user selects 'No', the input field is disabled and jQuery triggers a change event for AJAX form submission. $('#form-id').change(function(){ .... }); ...

Utilize CSS block display for ::before and ::after pseudo elements within a div container

I have a CSS file that contains the following code snippet: .loader { width: 250px; height: 50px; line-height: 50px; text-align: center; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-fam ...