Unable to discover a method to accomplish this task

Greetings to the Stack Overflow community!

I have a scenario with two div blocks containing images of dimensions 1280px width and 700px height each.

In the first block, there is a div with a width of 400px and a height of 100% floating left.

The second block also contains a div of the same size, floating right. The issue arises from the transparency at the bottom of the first block's image, about 10%.

On the other hand, the top of the second block's image is transparent by 10%. To connect them, I used margin-top on the second image. However, I am unable to hide these divs with a height of 100% beneath them. I attempted to use z-index, but it only hides one of the divs.

For a better understanding, please refer to this JSFiddle example: https://jsfiddle.net/c7m6pm4w/. In the JSFiddle, you will observe that the green and aqua sections are under the blue one. My goal is to have div.three (aqua) on top of div.four (blue) but beneath div.one (red), while div.two (green) should be on top of div.one (red) but beneath div.four (blue).

<div class="one">
  <div class="two"></div>
</div>
<div class="four">
  <div class="three"></div>
</div>

Here is a visual representation of the scenario: https://i.sstatic.net/9oIEL.png

Answer №1

In order to grasp your concept, I had to create some labeled paper stickers (the image in the original question was added later). From what I gather, you are looking for something similar to this:

https://i.sstatic.net/ylZOF.jpg

Unfortunately, achieving this using CSS, particularly with z-indexes, is not possible. Here's a breakdown:

zi4 < zi3 < zi1
zi1 < zi2 < zi4

zi4 < zi1
zi1 < zi4

Impossible.

While you can create the illusion of four overlapping items by using a fifth div colored like the first one, there is no practical reason for creating such an inconsistent and unsupported HTML structure. Hence, there is no conventional solution.

For further insight, you may refer to this related SO question, which includes an example of the "illusion" technique.
I have also prepared a JSFiddle specific to your scenario.

Answer №2

One simple approach that comes to mind is to divide everything into a nine-cells grid:

HTML:

<div id="b11" class="cell"> </div>
<div id="b12" class="cell"> </div>
<div id="b13" class="cell"> </div>
<div id="b21" class="cell"> </div>
<div id="b22" class="cell"> </div>
<div id="b23" class="cell"> </div>
<div id="b31" class="cell"> </div>
<div id="b32" class="cell"> </div>
<div id="b23" class="cell"> </div>

CSS:

div.cell {
    height: 100px;
    width: 150px;
}
#b11 {
    background-color: green;
    float: left;
}
#b12 {
    background-color: red;
    float: left;
}
#b13 {
    background-color: red;
    xfloat: left;
}

#b21 {
    background-color: green;
    float: left;
}
#b22 {
    background-color: white;
    float: left;
}
#b23 {
    background-color: aqua;
    xfloat: left;
}

#b31 {
    background-color: blue;
    float: left;
}
#b32 {
    background-color: blue;
    float: left;
}
#b33 {
    background-color: aqua;
    xfloat: left;
}

(You will need to adjust the widths and heights of each cell and add additional cells for the borders.)

Why not give it a try?

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

What is the best method for incorporating a unique style to a v-dialog component in Vuetify following the most recent update?

I'm currently working on a project using vuetify, and I am facing an issue while trying to add a custom class to a v-dialog component. I have tried searching for information on how to do this, but it seems that the prop "content-class" has been deprec ...

Is the button failing to direct you to the intended destination?

I'm facing an issue with a button tied to a JavaScript function using onClick(); My interface allows me to ban players on a game server, but when I select anyone here: https://i.stack.imgur.com/kcE1t.png, it always selects wartog for some reason. In ...

What can I do to prevent the border from breaking apart when I zoom in?

To address the problem of the 1px black border at the bottom of the header being cut off, try zooming into the page and scrolling right. How can this issue be resolved? ...

Why doesn't the z-index of child elements function properly when their fixed parents share the same z-index value?

I have utilized jsfiddle to replicate my problem. My goal is to position .top .inside above .bottom .inside. I am aware that z-index only functions within its respective position type, for example fixed and absolute do not share the same z-index level. How ...

HTML form not compatible with POST method in MVC

Why doesn't the $.post() method work in this case? I have tried pressing the button but it doesn't seem to post to EditClassLessonHour. This is the corresponding View Code: <div class="jumbotron"> <form id="editClassLessonHour"> ...

Angular2 poses a strange problem with ngClass

It seems like Angular is expecting me to use single quotes for the class names even if there are no hyphens in my CSS class name. I've tried everything but Angular keeps insisting on using hyphens for this specific CSS class... it's strange, or m ...

The AngularJS component materializes almost instantaneously

Using AngularJS, I have developed an application where a certain section of code is displayed after the page loads for a split second: <div class="col-sm-4" data-ng-repeat="user in users"> <div class="card"> ...

VueJs and the behavior of styling elements with inline CSS

Within my HTML, there is an <input> element that has the ability to change the background color of a <p> through an inline style. I conducted an experiment using two different methods to apply the style, and I encountered a peculiar behavior: w ...

Steps for eliminating the overlay on top of the padding region

My current code includes an overlay over images, but the overlay extends beyond the image itself and covers the padding area as well. If I switch the padding to margin in order to eliminate this unnecessary overlap, it causes the last image to be pushed on ...

Using AJAX to dynamically populate PHP form inputs from HTML

I'm trying to create a simple HTML form where users can input their information and have it sent to a PHP file using JavaScript with AJAX. However, I'm encountering an issue where the values from the form are not being included in the email that ...

How can the target pseudo-class be utilized to replace the 'active' state on navigation across several pages effectively?

Within a large application, I am managing a micro site and looking to implement tertiary navigation with an active state for pages. This involves inserting a single html blob into multiple pages. My goal is to use an active class to highlight the page in ...

Issue with navigator.geolocation.getCurrentPosition not functioning again on Firefox

I've encountered a peculiar issue with JQuery that has me seeking assistance. On a certain page, I have the following block of javascript code. Upon initial page load, everything works smoothly. However, if the user navigates away and returns to the ...

Image container unable to resize to fit within a CSS grid cell

I'm currently working on organizing a CSS grid for my images on a tribute page project from free code camp. I was able to set up the grid as intended, but I am facing some difficulties in making the images fit perfectly within each cell. Some images a ...

Display only alphabetic characters in the text field

I have a jQuery function that I am working on: $('#contact_name').on('input', function() { var input=$(this); var re =/^[A-Za-z]+$/; var is_email=re.test(input.val()); if(is_email) { } else { } }); This function is targeted at the fol ...

Enhanced spacing of characters in website text

Currently working on a client's website, I find myself once again being asked by my boss (who is the designer) to increase letter-spacing in the text for aesthetic reasons. However, I strongly believe that this practice can actually lead to eye strain ...

How can I make my webpage unselectable except for specific content within a div using CSS and JavaScript?

During a live editing session, I am looking to make only specific portions of the page selectable. Can someone provide guidance on how to disable selection for everything except within a particular div? ...

Embedding HTML in a Xamarin Forms Label

I am currently developing a mobile app for my website using Xamarin Forms. One of the challenges I am facing is styling HTML content stored in a database field. Although I am utilizing https://github.com/matteobortolazzo/HtmlLabelPlugin, I am struggling t ...

JavaScript expression not being processed

What could be the reason behind not receiving the value for dish.price, dish,description, etc.? Where am I making a mistake in this code snippet? <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="utf-8"> < ...

Utilize the grid system from Bootstrap to style HTML div elements

I am working on my angular application and need help with styling items in a Bootstrap grid based on the number of elements in an array. Here's what I'm looking to achieve: If there are 5 items in the array, I want to display the first two items ...

Every time I click the highlight button, my navbar link inexplicably shrinks

I am struggling with adjusting the list style in my bootstrap navbar. Whenever I click on the highlight button, it squeezes my navbar and I'm not sure how to fix it. <div id="links"> <a href="index.html">Home& ...