Utilize Z-index to hide elements from view

Encountering an issue with hiding other div elements when one is visible. In the code snippet below, I aim to make Pacific Rim and World War Z disappear using z-index when Star Trek is visible.

Here's my HTML code:

    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>BluShop</title>
    <link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="container">
    <header id="header">
        <h1>BluShop</h1>
    </header>

    <section id="leftContent">
        <div id="pacificrimContent">
            <h2>Pacific Rim</h2>
            <img alt="pacificrim image" src="../bilder/pacificRim.jpg">
            <p>Blahblahblah</p>
        </div>
        <div id="startrekContent">
            <h2>Star Trek</h2>
            <img alt="startrek image" src="../bilder/starTrek.jpg">
            <p>blahblahblah</p>
        </div>
        <div id="worldwarzContent">
            <h2>World War Z</h2>
            <img alt="worldwarz image" src="../bilder/worldWarZ.jpg">
            <p>blahblahblah</p>
        </div>
    </section>
    <aside id="rightContent">
        <div id="pacificrimPoster">
            <a href="#pacificrimContent"><img alt="pacificrim poster" src="../bilder/pacificRim.jpg"></a>
        </div>
        <div id="startrekPoster">
            <a href="#startrekContent"><img alt="startrek poster" src="../bilder/starTrek.jpg"></a>
        </div>
        <div id="worldwarzPoster">
            <a href="#worldwarzContent"><img alt="worldwarz poster" src="../bilder/worldWarZ.jpg"></a>
        </div>
    </aside>

    <footer id="footer">
    </footer>
</div>  
</body>
</html>

The CSS code

    @charset "utf-8";
/* CSS Document */

body{
    margin: 0;
    }

#container{
    width: 960px;
    height: 600px;
    margin: auto;
    background-color: rgb(78, 80, 85);
    border: solid 1px rgb(213, 214, 215);
    }

#header{
    height: 60px;
    background-color: rgb(66, 69, 74);
    margin-bottom: 10px;
    }   

#header h1{
    float: left;
    margin: 0px 10px 0px 10px;
    color: rgb(14, 177, 238);   
    }

#leftContent{
    float: left;
    position: relative;
    margin: 0px 10px 10px 10px;;
    height: 460px;
    width: 780px;
    background-color: rgb(230, 231, 232);
    }

#leftContent h2{
    font-size: 20px;
    margin: 10px 0px 0px 10px;
    }

#leftContent img{
    float: left;
    margin: 0px 20px 10px 10px;
    width: 310px;
    height: 420px;
    }

#leftContent p{
    margin: -4px 20px 10px 0px;
    }


#pacificrimContent, #startrekContent, #worldwarzContent{
    position: absolute;
    overflow: hidden;
    transition: height .5s ease-in;
    -webkit-transition: height .5s ease-in;
    -moz-transition: height .5s ease-in;
    }                   

#startrekContent, #worldwarzContent{
    z-index: -1;
    height: 0; 
    }

#rightContent{
    float: right;
    width: 140px;
    height: 460px;
    margin: 0px 10px 10px 10px;
    background-color: rgb(230, 231, 232);
    }   

#rightContent img{
    display: block;
    width: 100px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px    
    }   

#pacificrimContent:target, #startrekContent:target, #worldwarzContent:target{
    height: 100%;
    z-index: 10;
    }

#footer{
    height: 60px;
    margin: 0;  
    background-color: rgb(16, 163, 210);
    clear: both;
    }

Desiring Pacific Rim to always be visible initially on the website and having others appear when targeted. Currently facing an issue where Pacific Rim remains consistently visible in the background during transitions between Star Trek and World War Z.

Since JavaScript usage is restricted, seeking alternative methods to resolve this challenge. Appreciate any insights or suggestions!

Explore the issue further at jsfiddle.net/f8ns4 - JSFiddle demonstration available!

Answer №1

Make sure to give each of your movie divs a unique background color so that they cover up whatever is underneath.

#avatarContent, #inceptionContent, #interstellarContent{
    position: absolute;
    overflow: hidden;
    transition: height .5s ease-in;
    -webkit-transition: height .5s ease-in;
    -moz-transition: height .5s ease-in;
    background-color: rgb(150, 151, 152);
}   

Check out the demo here: http://jsfiddle.net/f8ns4/1/

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 ng-binding directive seems to be malfunctioning while ng-model is functioning properly

Currently, I am in the process of learning how to utilize Angular (1.3.10). My objective is to create two input fields that will specify the suit and value for a hand of playing cards. In my attempts to achieve this, I have encountered an issue. When I man ...

Using a URL in the fill property is a simple process that involves specifying

Here is the snippet of the code I'm working with: <?xml version="1.0" standalone="no"?> <html> <head> <style> .someClass { fill:"url(#Pattern)"; } </style> ...

How can I locate and modify particular element attributes within PHP files in a WordPress template?

Hello everyone, I am relatively new to the world of Wordpress and have recently taken over a project from another developer. The previous developer left behind default placeholders and texts that need to be updated. One specific change I need to make is to ...

How to position div elements side by side using CSS and center them, even on IE8

UPDATE: I have discovered that implementing Bart's solution is the correct one. With a 264px wide div containing the other divs and their 1px borders, I achieved the desired effect. I have updated my code to include his answer. Thank you, Bart. Once ...

Is there a way to prevent the text in my text boxes from staying there when I refresh the page?

Currently working on an HTML5 project with Javascript, here is a snippet of my code: Your inquiry <textarea type="text" name="phrase" id="phrase" cols="50" rows="5" placeholder="Write your text here. . ."></textarea> I am looking for a way ...

Guide on automatically extracting table rows and generating an Excel spreadsheet

I am currently working on a script that dynamically adds the first row (TH) to a table and then exports it to an Excel sheet. However, I am facing an issue where instead of appending each row, the script keeps stacking on top of the next table row. Below ...

Revamp the current webpage to display attribute values in textual format

As I peruse a webpage, I notice that there is room for improvement in terms of user-friendliness. The page is filled with a list of movie titles, each accompanied by a link to IMDb. However, the IMDB user rating is only visible when hovering over the titl ...

Managing the vertical positioning of grid items: tips and tricks

Is there a way to make the hexagons in my grid responsive to the layout, so that their height and width remain fixed relative to their container? Currently, they are overflowing from the grid container as shown in this jsfiddle: https://jsfiddle.net/gv5wc1 ...

How can I implement the Wordpress delete() function to remove a row from a table when a link is clicked?

I have a form on my site that collects data and stores it in the WordPress database. The information is then displayed on the same page in a table. Each row in the table has an "Action" column with a "Delete" link. My goal is to allow users to click the " ...

My efforts to resolve the issues in my code have been ongoing, but unfortunately, I have been unable to find a solution

I'm struggling to insert my contact form code into the contact tab without it interfering with the tab bar. I want the form to appear in the middle of the page when the tab is clicked. I've tried various placements for the code but none seem to ...

Ensure that the <aside> elements span the entire width of their containing parent element

I am currently designing a website and I am aiming for a specific layout. Any advice on how to achieve this would be greatly appreciated. The header of the page consists of: a logo aligned to the left within an <a> tag 2 widgets placed in <asid ...

Responsive Material-UI horizontal navigation bar

Hey there! I'm working on developing a UI using Material-UI, and I want to make it so that the menu can be collapsed into a slide-in style menu when accessed on a mobile device. Currently, I'm using tabs which allow for sliding left and right, b ...

Simple HTML/CSS text blocks positioned beside images in a list format

I'm attempting to design a list (ul) where each li has an img on the left and text aligned to the left (including a title and paragraphs) positioned next to the image on the right. I've experimented with float: left and various display propertie ...

Emptying the AnyChart (Javascript) container prior to generating new charts

I have been utilizing the anychart JavaScript library to generate a pie-chart from my data, which is dynamically pulled whenever a user modifies a dropdown selection. Below is the code snippet I am employing for this purpose: var stage = anychart.graph ...

Horizontal Screen Sharing on iPad

Currently, I have a two-column website set up using Wordpress. However, I am facing an issue with the right side column scrolling over on iPads. While the page behaves properly on desktops, on iOS devices, the div is able to scroll over the navigation ba ...

Chrome is the only browser displaying background images

My current issue is that the background image only appears on Chrome and not on Firefox or Edge. I am trying to have a different background image each time the page loads. $(document).ready(function() { var totalBGs = 5; var rnd = Math.floor(Math.ran ...

Eliminate the outline of the pager row in an asp.net grid view

Within my grid view, I have applied a bottom border to all cells. However, this border is also appearing on the pager row, which is not desired. To address this issue, I attempted to use jQuery to remove the border, but it seems that my selector is incorre ...

``Are you looking to create multiple canvases in a loop?

I've managed to get this command working exactly as I wanted: http://jsfiddle.net/m1erickson/64BHx/ However, I didn't anticipate how challenging it would be to turn the drawing into reality here: What I attempted to do is illustrated in this li ...

Identical HTML elements appearing across multiple DOM pages

My question might seem silly, but I'm facing an issue. I have several HTML pages such as index.html and rooms.html, along with a main.js file containing scripts for all of these pages. The problem arises because I have variables like const HTMLelemen ...

Issue encountered while attempting to include a background image in React JS

I encountered an issue when attempting to include a background image in react js. ./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css) Unable to locate module: An attem ...