Displaying divs inline with overlapping child divs

As a beginner in CSS, I tackle the challenges of learning it every day. Despite feeling clumsy and not naturally adept at it, my determination is strong (although sometimes my brain feels like an old computer on the verge of overheating). My current goal is to figure out how to code a group of individual modules that share the same style and are arranged in two rows of two columns inline. Each module should be represented as a paper stack utilizing z-index and absolute positioning.

To illustrate what I have in mind, I created this image:

In my attempt, I experimented with display:inline for the top div, but it required me to code separate, overlapped divs for each module using position:absolute and specific coordinates. Ideally, I would like to create a single module with overlapping sections that can be duplicated simply by applying the same class (without the need to adjust the coordinates of every individual module).

If anyone has a solution or suggestion on achieving this layout using CSS, I would greatly appreciate your input. Thank you in advance :)

Answer №1

Indeed, you have the option to proceed as follows. Feel free to adjust the dimensions to your preference. Check out the JSfiddle demonstration here: http://jsfiddle.net/CNPJ9/2/

<div class="contain">
    <div class="box">
         <h1>A</h1>

    </div>
    <div class="behind"></div>
</div>
<div class="contain">
    <div class="box">
         <h1>B</h1>

    </div>
    <div class="behind"></div>
</div>
<div class="contain">
    <div class="box">
         <h1>C</h1>

    </div>
    <div class="behind"></div>
</div>
<div class="contain">
    <div class="box">
         <h1>D</h1>

    </div>
    <div class="behind"></div>
</div>

.contain {
    margin:25px 25px;
    float:left;
}
.box h1 {
    font: 8em normal Futura, sans-serif;
    text-align:center;
    color:#f1f1f1;
}
.box {
    width:400px;
    height:300px;
    background:#000;
    z-index:1;
    float:left;
    position:absolute;
}
.behind {
    width:350px;
    height:325px;
    margin-left:25px;
    background:#333;
    z-index:2;
}

Answer №2

If you're looking for a solution, consider trying something like this: Check out this Fiddle

.abc{
    width=300px;
    height:200px;
    margin:50px;
    border:solid 2px black;   
    border-bottom: 5px double blue;
}

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

Creating an online bidding platform using ASP.Net, MVC 5, and Entity Framework

Having recently delved into the world of ASP.NET, I am in the process of developing a basic auction site for a charitable cause. Utilizing MVC 5 and Entity Framework with Code-First approach for database management. The core of this project is the Item mo ...

Deliver acquired post information to HTML using the read file technique

I've been diving into the world of nodeJS, jquery-mobile, and HTML5. Below is a snippet of my code: Fetching post data from an html form: req.addListener("data", function(postDataChunk){ postData += postDataChunk; console.log("Received POST ...

Ensure that the Div element remains visible on the screen while contained within a

Is there a way to maintain the position of elements on the right side of a div without using position: fixed, while still keeping the div within its parent container? See the desired layout. I need the "Stays in view" element to stay within its parent div ...

Can Selenium be executed from a <py-script> within an HTML file?

prefs = webdriver.ChromeOptions() prefs.add_experimental_option("detach", True) driver = webdriver.Chrome(ChromeDriverManager().install(), options=prefs) Following this code, it seems to stop running (It runs fine in a .py file so I believe all ...

Easy-to-use form input ensuring a constant total of 100

Looking for a way to collect numerical values from users that total 100% on a dynamically generated form? I'm exploring the idea of using a script or algorithm to adjust text fields as values are changed, ensuring they always add up to 100%. However, ...

Ways to conceal a div using ng-hide

Is there a way to make a div disappear using ng-hide? I have this code and I'm trying to hide the div with id="ApagarNA". The code displays a table with values, but some rows contain N.A in all 4 columns, and I want to hide those specific rows. For e ...

Picture with predetermined size to occupy entire container

Seeking assistance! I am looking to pixelate an image after a jQuery event without using plugins like pixelate.js as they are not suitable for my project. Is it possible, through CSS or JavaScript, to automatically change the image to a smaller version wi ...

Issue with JQuery causing maxlength input not to work

Is there a way to use JQuery to set the maxlength attribute for an input[type='text'] while users are typing, so that once the max value is reached, input will stop? This is the code I have been trying: $(document).ready(function(){ $(&apos ...

What is the best way to enable my search function to filter out specific items from a table?

Currently, I have created a table populated with data fetched from a JSON file. Now, my focus is on implementing a search functionality that filters out items based on user input and displays only those table rows matching the search criteria. The code sni ...

Basic PHP code for fetching outcomes

Looking to retrieve results from a website by utilizing a for loop to gather and compile them together. (Please note that it involves an ASP request which generates a webpage with specific parameters) I have drafted this code in attempt to achieve the de ...

An unexpected background image appearing from an external CSS file

I need to dynamically change the background image of a class using an external CSS file. The image should be randomly selected from a specified path. While I know how to achieve this in PHP, I am looking to implement it in the external CSS file instead. ...

Problem with logo in MVC4 apps

I'm working on incorporating a logo into my MVC 4 website. When the logo is clicked, it should navigate to the home screen. In order to achieve this, I've added the following code snippet in the _Layout.cshtml file. <a href='<%= Url.A ...

Top method for utilizing jQuery to locate, sift through, and implement CSS classes

Let's consider the following scenario: <span class="foo">7</span> <span class="foo">2</span> <span class="foo">9</span> We want to assign a CSS class of 'highest' to 'span.foo' with value great ...

Ionic Troubleshoot: Issue with Reading Property

Encountering an error: A TypeError occurs: Cannot Read Property of "username" of Undefined The HTML code responsible for the error is as follows: <ion-content padding style="text-align: center; margin-top: 35px"> <form (ngSubmit)="logFor ...

Bootstrap Model Footer Button Alignment

click hereI'm facing an issue while adding buttons to the model footer. The buttons are not aligning in line, instead they move to the next line. <div class="modal-footer"> <form method="post" action="admin_view"> ...

Switching from a click event to a hover event in JavaScript

I've been experimenting with animating a burger bar on hover and came across an example online that I managed to adapt for mouseenter functionality. However, I'm struggling to make it revert back to the burger bar shape once the mouse leaves on m ...

What is causing the CSS transition to fail in the updated DOM?

When attempting to apply a CSS transition as shown in the following code snippet: https://jsfiddle.net/sunyuu/e58sfeva/17/ var Main = { data () { return { isActive: false, childStyle: {} }; }, methods: { sho ...

Ensure the scrollbar is noticeable and personalized solely within a designated div, such as the left side menu

In the left side menu, I have set the overflow-y: scroll property and a fixed height that is smaller than the entire page's height. I am trying to make the scrollbar always visible only within this left menu. I attempted using -webkit-scrollbar and -w ...

Obtain the Chosen Item from a List Box Using JQuery and Separate by Commas

Seeking further assistance with the following issue. I have set up the code on jsfiddle at... http://jsfiddle.net/justinerswell/feDTU/ I am looking to extract the last item in the substr and then work backwards to fill in the necessary fields. Appreciat ...

How can I prevent or override the text being pushed to the right by CSS::before?

Using the css property ::before, I am attempting to insert a tag before a paragraph. While I am able to display the tag correctly, it is causing the text within the paragraph to be shifted to the right. Ideally, I would like the tag to appear in the top-le ...