Conceal the parent div from its sibling within the same parent container

My goal is to conceal a parent component from its child element. I attempted to achieve this by using the parent component as a background while adding additional backgrounds to the child elements for overriding purposes. However, this method did not work well for me due to certain frontend issues.

Is there a way to hide child1 (when it is set to absolute positioning, as that is the only layout that functions correctly on my frontend for design reasons) from child3 when it becomes visible on child2?

Thank you in advance for any insights or suggestions.

<main className="mainbg">
    <div className="child1">
              a component along the page. from top to bottom. see css.
    </div>
    {/*/ <Awesomeslider> /*/}
    <div className="child2">
         firstslide
    </div>
    <div className="child3">
        rightslide
    </div>
    {/*/ <Awesomeslider/> /*/}
</main>

//Slider with React.js = awesomeslider
.mainbg {
    width: 100vw;
    height: fit-content;
    display: block;
    background: linear-gradient(/*/ some gradient along the page including sliders /*/);
}
.child1 {
    position: absolute;
    top: 0;
    width: 50vw;              /*/ will be setted as it will be fit along full page from main to child2, but it must be hidden in child3 /*/
    margin: auto;
}
.child2 {
    width: 100vw;
    height: fit-content;            /*/ child1 will be visible here /*/
}

.child3 {
    width: 100vw;
    height: fit-content;              /*/ child1 won't be visible here /*/
}
<div id="root"><div/>

Additional Draft:

Answer №1

To hide certain elements, simply include z-index: -1. Conversely, to display a specific element, apply z-index: 1.

Keep in mind that the z-index property will only take effect if the element also has position: ANY_POSITION specified.

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 DOM is failing to refresh in Vue.js even after the array has been updated

After receiving a list of items using AJAX, I store them in a data Array: loadSparepartFiles: function() { var vm = this; vm.activeSparepart.attachments = []; ajaxApi.loadJson('spareparts/sparepart/getFiles/'+vm.activeSparepartId, fu ...

Deleting content from cells in table for all even td items

This problem has been causing me frustration; I've attempted various methods using jquery and CSS, but to no avail. Essentially, I have the following table structure: <table id="mainTable"> <thead> <tr> <th>Arrival ...

Guide for redirecting puppeteers' attention to a new pop-up interface

Currently, I am utilizing Puppeteer to carry out a test on a website. Upon clicking a button, a new popup browser window emerges displaying a report. Inside this new window lies data that I wish to extract. Is there a method for Puppeteer to switch its foc ...

Compilation unsuccessful. The LineGraph.js module could not be located due to recursion in resolving

After successfully installing react-chartjs-2 and chart.js using the command npm install --save react-chartjs-2 chart.js, I encountered an error when attempting to use LinkGraph: Failed to compile. ./src/LineGraph.js Module not found: Recursion in resolvi ...

Tips for sending an ID to a path link in React Js

Can anyone assist me in setting up a path for a component like this "/products?id=uniqueId" in my React Js Project? The unique id is retrieved from the database and varies depending on the product chosen. Below is an excerpt of my code: CodeSandbox App.j ...

Avoid stretching the div to the edge of the screen

In the table on my page, I have implemented a feature using CSS to display additional information in a popup div. This works well when there is limited text, but if there is extensive text in the table, it extends beyond the screen width and becomes diffic ...

Is it possible to add data in MongoDB without specifying a field name?

I have a couple of queries that revolve around the same concept: If I want to insert a new 'row' in MongoDB, can I do so by specifying the order of the fields? For instance, if my collection looks like items = { { name: "John", age: "28" ...

I am having trouble connecting my CSS file to my EJS file

I'm having trouble including my external main.css file in my header.ejs file. I've designated my CSS file as public in my backend Node.js with Express.js server (index.js) using this static code: app.use(express.static("public")); The ...

Exploring the filter method in arrays to selectively print specific values of an object

const array = [ { value: "Value one", label: "Value at one" }, { value: "Value 2", label: "Value at 2" }, { value: "" , label: "Value at 3" } ...

What could be causing the "Undefned Jquery-ajax" error to pop up

I am struggling with the following code. My goal is to populate values into a dropdown <select> box, but I keep receiving an error of undefined. I have tried switching between Object.keys and Object.values, however, I am still facing the same issue. ...

Issue arises when trying to display a component located in a separate file upon clicking a button

I am currently working on a React website that features a navigation bar built with Material-UI. My main challenge lies in switching between different components, such as "About" and "Home", based on the user's selection from the navigation bar. As a ...

Even though I'm using the useRef() hook within the useEffect hook, node.current is still appearing as null

My objective is to create a large scrollable modal that automatically scrolls to the top when the content within it changes. I am facing challenges as I cannot access the window object, so I have been advised to use a ref. However, I am encountering the er ...

What is the best way to implement filter functionality for individual columns in an Angular material table using ngFor?

I am using ngFor to populate my column names and corresponding data in Angular. How can I implement a separate filter row for each column in an Angular Material table? This filter row should appear below the header row, which displays the different column ...

Creating unique CSS class and ID names dynamically in PHP

I have two divs with randomly generated IDs and I would like to use those IDs in my CSS instead of using inline styles. Is there a way to achieve this without creating a separate PHP file with a CSS header? For example, I want the padding for the ID $id_ ...

Simultaneously scrolling left and fading in with jQuery

I've come across this code that works well in scrolling my divs to the left. However, I'm looking to add a fading effect while they are scrolling. Is there a way to achieve this? $('div#line1').delay(1000).show("slide", { direction: "r ...

Hover functionality in autocomplete feature malfunctioning

My Autocomplete component relies on the selected value of the parent Autocomplete, and it's been working perfectly. Typing or hovering to select both work as expected. const [hoverd, setHoverd] = useState(false); const onMouseOver = () => setHoverd ...

Issues with Displaying Components Generated from an Array in JSX

I have a task variable which has the structure as follows: [ team_id_1: { task_id_1: { description: ... }, task_id_2: { description: ... } }, team_id_2: { ... } ] When trying ...

Arrange text boxes within a form and table to be in alignment with the labels

https://i.stack.imgur.com/MFQnD.png I'm facing difficulty aligning checkboxes with labels within a form and a table. Despite reviewing various answers and websites, I am still unable to achieve the desired alignment. How to consistently align check ...

Adjust the text size of Twitter Bootstrap on mobile screens

I recently started using Twitter Bootstrap. I am currently hiding certain <tr> elements on phone screens by utilizing the class="hidden-phone". However, I am now looking to resize the displayed text to better fit the screen. Is there a way to adjus ...

Access to JSON.stringify is prohibited

I have an array containing objects in JavaScript that I need to save as a .json file. Prior to saving the objects, I displayed them using console.log. // Client Object {id: "1", color: "#00FF00"} Object {id: "2", color: "#FF7645"} Object {id: "3", color: ...