SCSS - Hide div1 when div2 is hovered over

In an attempt to make a div disappear when hovering over another div using only CSS, I have set up two divs:

<div class="" id="target">I will disappear</div>
<div class="hover_box">Hover me</div>

Here is my SCSS code:

#target {
  background-color: blue;
  height: 100px;
  width: 100px;
}

.hover_box {
  background-color: red;
  height: 100px;
  width: 100px;

    &:hover #target{
      display: none !important;
      /* background-color: green !important; */
    }
}

Unfortunately, this setup does not seem to work as intended. You can view the issue in action here:

https://jsfiddle.net/ubLLga3q/3/

Answer №1

Your current issue lies within the HTML markup. You are attempting to make #target disappear on hover, but you can only achieve this by targeting a sibling or child element. As it stands, #target is not a child of .hover_box.

<div class="box">
  Hover over me
   <div class="hover_box">

  </div>
</div>

.box {
  background-color: blue;
  height: 100px;
  width: 100px;
}

.hover_box {
  background-color: red;
  height: 100px;
  width: 100px;
}

.box:hover .hover_box {
  display: none;
}

https://jsfiddle.net/ubLLga3q/6/

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

A guide to quickly obtaining the width and height of an element as it resizes in Vue.js

Is there a way to immediately get the width and height of an element when it is resizing in Vue.js? I have created a Codepen illustration and would appreciate any help in making it function correctly, thank you! Codepen let app = new Vue({ el: &apos ...

Angular 5 is not compatible with jQuery

I'm attempting to integrate jQuery into my Angular 5 project, focusing on utilizing this specific library: https://codepen.io/rstrahl/pen/eJZQej Below are the steps I've followed: -->Created a new app ng new myApp -->Navigated to the n ...

Steps to retrieve the primary key associated with a duplicate entry error (1062) in MySQL using the Knex.js library

Testing out the database by sending values from an HTML form has been successful so far. Unique inserts and good connections are working well. However, intentionally sending a duplicate username for testing purposes results in an error message - which is e ...

Searching through the Symfony2 database with the help of Select2 and Ajax

Currently, my FAQ System is running smoothly. However, I am looking to enhance it by adding a search function using Select2. Here's what I have so far: Select2 AJAX Script <script> $("#searchall").select2({ ajax: { ...

Error: The function onSelectChange is not defined in this.props

Currently, I am attempting to connect a state from the Parent component App.jsx class App extends Component { constructor() { super(); this.state = { select: '', }; this.onSelectChange = this.onSelectChange.bind(this); ...

Encountering an "Unspecified Reference Error" while attempting to retrieve data from an API in your

I've been attempting to utilize a mock API from in order to fetch data for my Next.js application. However, I am consistently encountering an undefined reference error, despite following the code snippet provided in the official Next.js documentation ...

Using a combination of a bootstrap class and a custom CSS class to enhance your website design

How do I apply two different classes? I have two HTML select fields where the user can choose either repair or another option in the first one. When the user selects one, the second field should appear. But it also needs to have a Bootstrap class: form-con ...

CSS: "Cutting-edge" design. In what way?

I am seeking to replicate a design similar to that of Fantastical's website (https://flexibits.com/fantastical), where the edge of a screenshot extends beyond the page boundary. As the user resizes the window, more of the screenshot becomes visible. A ...

How to properly format JSON responses in Node.js or Express

I came across a question on Proper way to return JSON using node or Express and copied it for reference. I am looking for the response in a specific format. This is the sample format for the response API: { "success":true, "code":200, "message":"Ok", "da ...

Error in displaying image when lightboxv2.6 is clicked

I am having an issue with my lightbox 2.6 setup. The thumbnails are displaying correctly, but when I click on an image, the lightbox appears, however, the image does not load and it continues to show the loading icon. Here is my code snippet: <!docty ...

When the page reloads, the firebase currentUser variable is found to be

Currently utilizing Firebase for authentication. Prior to making a request to the backend, I always ensure to request the idToken. service.interceptors.request.use(async request => { const token = await firebase.auth().currentUser.getIdToken(); i ...

What is the best way to eliminate tags within a tag using PHP?

As a beginner in regex, I've been trying to extract content from a website. Sometimes the content on the website is structured like this - Example 1: <strong> text </strong><strong><a href="" target="_blank"> text </a> ...

How can Socket.io prevent other pages from receiving all messages?

I apologize for the confusing title, but I am in need of some assistance in clarifying my question. The situation is as follows: I have a website page that is receiving messages from a node server. socket.on('item finished', function(data){ ...

Transforming a pseudo element from horizontal to vertical orientation

I have a unique snippet of code that generates an element at the bottom of a div to serve as an inventive 'arrow/pointer' pointing down. Now, I am seeking assistance in tweaking the script so that the 'arrow/pointer' directs towards th ...

Component re-rendering and initializing useReducer

I made some revisions to this post. Initially, I shared the entire problem with my architecture and later updated it to focus directly on the issue at hand in order to make it easier for the community to provide assistance. You can now jump straight to the ...

Tips on dynamically passing values according to media queries

Within my product section, there is a total of approximately 300 products. To implement pagination, I have utilized the ngx-pagination plugin. The products need to be displayed based on media query specifications. For example, if the viewport size falls wi ...

You can activate Lightgallery just one time in VueJs

I am facing an issue where lightgallery can only be opened once. Subsequent clicks on the button are unresponsive. The lightgallery is being used as a component. Within my parent component, I have two buttons for opening image or video gallery ParentComp ...

Building upon the preceding inquiry, a ReferenceError has occurred due to the object being undefined

After researching online, I came across a similar question marked as a duplicate that brought me to this link: How do I return the response from an asynchronous call?. Even though I couldn't find a solution in that thread, it seems like I may need to ...

The functionality of localStorage seems to be dysfunctional in Nuxt js when running in SSR mode

I am encountering an issue while trying to add items to a cart using vuex. The console is showing an error and the products on the page are not displaying correctly. Can someone please guide me on how to resolve this problem? The error in the console is: c ...

Verify the presence of a JSON object within the session storage using JavaScript

I'm currently developing a website where some data is stored within the session. In the initial page, I need to verify if the JSON object already exists in the session. Below is the code snippet that's causing issues: var passedTotal = JSON.par ...