Unable to show buttons when hovering over them

My goal is to have a set of buttons displayed when the user hovers over a specific button (Settings). I managed to achieve this by hiding the Settings button when the user hovers over the current div element and showing the other buttons instead.

<div class="md-card container">
    <p matLine><b>{{message.artifactId}}</b></p>
    <p matLine>
        {{message.groupId}} &nbsp;&nbsp; {{message.version}}
        <button type="submit" class="btn btn-danger pull-right settingsbtn">
            <i class="material-icons">settings</i>
        </button>
        <a routerLink="/baseline-errors/{{message.id}}">
            <button type="submit" class="btn btn-danger pull-right listbtn">
                <i class="material-icons">content_paste</i>
            </button>
        </a>
        <button *ngIf="isScanning" type="submit" class="btn btn-danger pull-right spaceTest listbtn"
                (click)="rescanBaseline(message)">
            <i class="material-icons">refresh</i>
        </button>
        <button type="submit" class="btn btn-danger pull-right listbtn"
                (click)="deleteBaseline(message)">
            <i class="material-icons">delete</i>
        </button>
        <button type="submit" class="btn btn-danger pull-right listbtn"
                (click)="editBaseline(message)"><i
                class="material-icons">mode_edit</i>
        </button>
    </p>
    <mat-divider></mat-divider>
</div>

CSS

.listbtn {
    opacity: 0;
    transition: opacity .35s ease;
}

.container:hover .listbtn {
    opacity: 1;
}

.settingsbtn {
    opacity: 1;
    transition: opacity .35s ease;
}

.container:hover .settingsbtn {
    opacity: 0;
}

The above code works as expected for the entire div element, but my goal now is to hide the Settings button and show the other buttons when the user hovers over it. I modified the code as follows:

<div class="md-card container">
    <p matLine><b>{{message.artifactId}}</b></p>
    <p matLine>
        {{message.groupId}} &nbsp;&nbsp; {{message.version}}
        <span class="sd">
        <button type="submit" class="btn btn-danger pull-right settingsbtn">
        <i class="material-icons">settings</i>
        </button>
        <a routerLink="/baseline-errors/{{message.id}}">
            <button type="submit" class="btn btn-danger pull-right listbtn">
                <i class="material-icons">content_paste</i>
            </button>
        </a>
        <button *ngIf="isScanning" type="submit" class="btn btn-danger pull-right spaceTest listbtn"
                (click)="rescanBaseline(message)">
            <i class="material-icons">refresh</i>
        </button>
        <button type="submit" class="btn btn-danger pull-right listbtn"
                (click)="deleteBaseline(message)">
            <i class="material-icons">delete</i>
        </button>
        <button type="submit" class="btn btn-danger pull-right listbtn"
                (click)="editBaseline(message)"><i
                class="material-icons">mode_edit</i>
        </button>
        </span>
    </p>
    <mat-divider></mat-divider>
</div>

CSS

.listbtn {
    opacity: 0;
    transition: opacity .35s ease;
}

.sd:hover .listbtn {
    opacity: 1;
}

.settingsbtn {
    opacity: 1;
    transition: opacity .35s ease;
}

.sd:hover .settingsbtn {
    opacity: 0;
}

Unfortunately, this modification did not produce the desired outcome. What am I missing in my approach?

EDIT

I intend to have the Settings button visible initially, and upon hovering over it, it should be hidden while displaying the other buttons. However, if the user hovers over the other buttons initially, they should remain invisible. The current code snippet results in displaying all buttons upon hovering over any button, which is not the desired behavior.

Answer №1

Here is the CSS code that you can use:

.listbtn {
    opacity: 0;
    transition: opacity .35s ease;
}

.settingsbtn:hover ~ .listbtn,.settingsbtn:hover + a .listbtn {
    opacity: 1;
}

.settingsbtn {
    opacity: 1;
    transition: opacity .35s ease;
}

.settingsbtn:hover {
    opacity: 0;
}

.listbtn {
    opacity: 0;
    transition: opacity .35s ease;
}

.settingsbtn:hover ~ .listbtn,.settingsbtn:hover + a .listbtn {
    opacity: 1;
}

.settingsbtn {
    opacity: 1;
    transition: opacity .35s ease;
}

.settingsbtn:hover {
    opacity: 0;
}
<div class="md-card container">
    <p matLine><b>{{message.artifactId}}</b></p>
    <p matLine>
        {{message.groupId}} &nbsp;&nbsp; {{message.version}}
        <button type="submit" class="btn btn-danger pull-right settingsbtn">
        <i class="material-icons">settings</i>
        </button>
        <a routerLink="/baseline-errors/{{message.id}}">
            <button type="submit" class="btn btn-danger pull-right listbtn">
                <i class="material-icons">content_paste</i>
            </button>
        </a>
        <button *ngIf="isScanning" type="submit" class="btn btn-danger pull-right spaceTest listbtn"
                (click)="rescanBaseline(message)">
            <i class="material-icons">refresh</i>
        </button>
        <button type="submit" class="btn btn-danger pull-right listbtn"
                (click)="deleteBaseline(message)">
            <i class="material-icons">delete</i>
        </button>
        <button type="submit" class="btn btn-danger pull-right listbtn"
                (click)="editBaseline(message)"><i
                class="material-icons">mode_edit</i>
        </button>
    </p>
    <mat-divider></mat-divider>
</div>

Answer №2

It appears that your code is functioning correctly, is this the desired outcome?

.listbtn {
    opacity: 0;
    transition: opacity .35s ease;
}

.sd .settingsbtn:hover ~ .listbtn {
    opacity: 1;
}

.settingsbtn {
    opacity: 1;
    transition: opacity .35s ease;
}

.sd .settingsbtn:hover {
    opacity: 0;
}
<span class="sd">
<button type="submit" class="btn btn-danger pull-right settingsbtn">
<i class="material-icons">settings</i>
</button>
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">content_paste</i>
</button>
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">refresh</i>
</button>
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">delete</i>
</button>
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">mode_edit</i>
</button>
</span>

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

"Implement a smooth transition effect lasting 1000 milliseconds when a class is added via

I'm attempting to use the fadeIn 1000 effect when a class is added through a Click function. I have already attempted this: http://jsfiddle.net/rf7mudL5/ HTML <span class="date-outer">Text will Red on fadeIn</span> <button class="mo ...

Trying out the combination of @inject parent and @contentChildren in practice

I have been working on developing a unique custom tab component that consists of both parent and children elements structured as follows: Parent @Component({ selector: 'app-custom-tabs', template: ` <div class="inline-flex"> ...

Navigating through error messages in NextJs 14 can be tricky, especially when faced with the dreaded "ReferenceError: document not defined" or "prerendering error". It's vital to pinpoint exactly which page

When attempting to run the build on my Next.js application, I encountered an error message that is not very informative given the number of files/pages in my project. How can I pinpoint the exact location of this error and determine the root cause? The pro ...

Loading an external script is causing a total style overhaul on my website

Every time I load my page to check the remaining balance of a gift card (using a third-party script), it seems to mess up the styles that are already set on my website. Here is a snippet of the code causing the issue: <div id="main" class=&quo ...

Is there a way to change a DWG file into a Flash (SWF) file?

Looking for a way to convert DWG and DXF files into SWF format directly from the client's browser. These files are currently stored on the server, and the converted file will also be saved there. I have searched for software options but haven't ...

display or conceal a div when a radio button is selected

I need a way to display a specific div containing unique text once a radio button is selected, while hiding all other div sections. <?php foreach ($items as $item){ $i=1; echo ' <div class="form-check"> <input class="fo ...

Is there a way to verify if any updates have been made to the HTML code

Sorry if this isn't the right place to ask, but I'm not sure where else to go. We are creating a Firefox addon that functions on certain websites. Because these sites are subject to occasional changes, I want to run a JavaScript script once a da ...

Is there a way to combine multiple incoming WebRTC audio streams into one cohesive stream on a server?

I am currently working on developing an audio-conferencing application for the web that utilizes a WebSocket server to facilitate connections between users and enables streaming of audio. However, I am looking to enhance the system by transforming the serv ...

Tips for waiting in Angular 7 until the DOM is fully loaded and ready?

Currently, I have a situation where clicking on an entry triggers an HTTP request to load data into a table. This works fine individually. However, when trying to create an export function to output all tables at once, the code looks something like this: ...

Retrieve all hyperlinks within a table using Beautiful Soup

<td style="text-align: center;"><a title="Some unique title" href="https://www.uniquewebsite.com">Unique Testing Content</a></td> I am attempting to accomplish the task of using BeautifulSoup to retrieve all the href links within a ...

Press a specific button within a row displayed in a table

I have a table displayed below: <table id="tabmailveille"> <tr><td> <button onclick="return Ajax(162, {'idc': '125').value,'action': 'ajout'});"><img alt="Add" src="/Images/tableaux/add.pn ...

What is the best method to showcase the value in HTML using either Angular or JavaScript when the return is true or false?

Just a heads up: The code snippet below is all about logic, so no parameters have been defined. However, they are actually defined and actively used in the same javascript file that I'm diving into. My venture into javascript/angularjs (not quite sur ...

Clicking on a link in HTML with the onclick event

I am looking to create a button that will direct me to a different page. Here is the code snippet I have: <div align="right" ><input type="submit" id="logout" onclick="location.href='/login?dis=yes'" value="Sign Out" ></div>& ...

Tips for utilizing jest.mock following the removal of @types/jest (^jest@24)

After upgrading from version 7 to version 8 of @angular-builders/jest, I followed the instructions provided in the migration guide which advised removing @types/jest since it now comes bundled with Jest v24. Additionally, changes were made to my tsconfig a ...

How to store property transformation in Redux/ngrx

I have the following setup someReducer.ts export interface State { someProp: MyModel; } // some action listeners .. // // export const getProp = (state: State) => state.someProp; selector.ts export const getProperty = createSelector(getState, f ...

"Utilizing ng class with an array of objects: A step-by-step guide

I am facing a scenario in which my response appears as follows: "currency" : [ { "_id" : ObjectId("584aad5d3e2537613e5f4c39"), "name" : "USD" } ], I need to enable my checkbox based on the currency name. I attempted the followi ...

.scss compiling with errors

Recently, I embarked on a new Vue(3) project. Within this project, I have set up some basic styling in the App.scss file and created a HomeView.vue with a corresponding HomeView.scss file (located in the /src/views/Home directory). The styling from both fi ...

Enhance your Javascripts by incorporating Try Catch statements

I have two sets of scripts, CODE#1 and CODE#2. The first set contains a script that sources data from a web service. I want to implement a try catch mechanism in the second set (CODE#2) so that if the web service is inaccessible due to site downtime, an al ...

I am looking for unique values from a duplicate string that is separated by commas in TypeScript

Using TypeScript, I am trying to extract unique values from a list of comma-separated duplicate strings: this.Proid = this.ProductIdList.map(function (e) { return e.ProductId;}).join(','); this.Proid = "2,5,2,3,3"; The desired output is: this. ...

What is the best way to align a div of variable size in a container of variable size using CSS?

My website features a 3-level structure that consists of a "workingArea" and an "imageContainer" within it, containing an image. <div class="workingArea"> <div class="imageContainer"> <img class="theImage" /> </div> </div> ...