Customizing CSS in Blazor on mouseover with multiple displayed divs

@foreach (var item in RootOfJson.results)
{
<div class="card" @onmouseout="@OnMouseOut" @onmouseover="@OnMouseOver"> 
<img class="@Imgdisplay" <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedddccd93eec7dacbc380c7c3cfc9cb">[email protected]</a>_url  alt="...">                                            
</div>
}
    

@code {

bool _IsHovering = false;
[Parameter]
public string Imgdisplay { get; set; }

 protected void OnMouseOver(MouseEventArgs mouseEvent)
    {
        if (!_IsHovering)
        {
            _IsHovering = true;     
            Imgdisplay = "d-none";
            StateHasChanged();
        }
    }

    protected void OnMouseOut(MouseEventArgs mouseEvent)
    {       
        Imgdisplay = String.Empty;        
        _IsHovering = false;
        StateHasChanged();
    }

The code snippet above is for changing the css class for all divs. However, I am looking for assistance to modify it so that the class is changed to d-none only on the specific div where the mouse event occurs.

Answer №1

Whenever you hover over a certain division, the OnMouseOver method is triggered, changing the value of _IsHovering to true and hiding Imgdisplay by setting it to "d-none". All div elements utilize _IsHovering, resulting in a uniform CSS modification for all div elements.

My suggestion would be to create a distinct component and encapsulate the div along with its related functionalities (such as _IsHovering or Imgdisplay) within it. This approach ensures that each div operates independently and does not share its state with others.

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

Error: Unable to retrieve the value of a null property | ReactJS |

There are two textboxes and one button designed as material UI components. </p> <TextField id="chatidField" /> <br /> <p> <code>Enter Your Name:</code> <hr /> & ...

Ways to showcase a list in 3 columns on larger screens and 1 column on smaller screens

When viewing on a computer, my list appears like this: https://i.sstatic.net/fNhaP.png However, when I switch to a phone, only the first column is visible and the list does not continue in a single column format. I am utilizing Bootstrap for my layout, a ...

What is the method for customizing the color of the drop-down arrow in

Is it possible to customize the color of the dropdown arrow while maintaining the same style? #cars{ width:150px; } <!DOCTYPE html> <html> <body> <select name="cars" id="cars"> <option value="volvo">Volvo</option& ...

Showcasing the values of JavaScript

How can I resolve the issue depicted in the second picture? I need the value of 3 only in the USD column, with all others having a value of zero. <div class="span3"> <ul class="nav nav-tabs nav-stacked" > <?php foreach ( ...

Measure with an "em" unit indicated by a dot

Could you clarify if there is a distinction between writing padding:.6em and padding:0.6em; and if they have the same value, why not just use padding:0.6em; ? Thank you ...

Introduce new material at the start of each line, akin to what ::before accomplishes for the initial line

I am currently working on customizing the appearance of my <code>/<pre> tags while ensuring that users can still easily highlight and copy the code. The method I had in mind (shown below) only applies to the first line and doesn't repeat ...

Using jQuery and CSS to create a temporary placeholder for images that have varying sizes

I am currently developing an innovative image gallery feature where a temporary heart image is displayed for 1 second in place of the actual images (image 1, image 2 etc). If you want to view the implementation, check out my jsfiddle below: https://jsfid ...

In React, when utilizing the grid system, is there a way to easily align items to the center within a 5 by

I need to center align items within the material-UI grid, with the alignment depending on the number of items. For instance, if there are 5 items, 3 items should be aligned side by side in the center and the remaining 2 items should also be centered. Pleas ...

After encountering a character with CSS, begin a new line

I have a CSV spreadsheet with data that looks like this: <p>Features:• first feature• second feature• third feature• fourth feature• and so on (the total number of features is variable)</p> I want each feature to display on a new li ...

Position CSS elements at the bottom of the webpage

I'm having trouble with my footer always being covered by dynamic content on my page. How can I adjust the CSS to make sure the footer stays at the bottom and adjusts to the size of the content? Here's the current CSS code for the footer: div ...

Ways to fix text overlap in a pill

Click here to view the code on jsBin I quickly copied HTML/CSS code to jsBin using a tool called SnappySnippet. I attempted various solutions, but none of them worked. The best option for me seems to be overflow: ellipses word-break: break-word; word-b ...

Set the position of a div element to be fixed

I am currently working on a straightforward application that requires implementing a parallax effect. Here are the methods I have experimented with so far: - Inserting an image within a div with the class parallax. - Subsequently, adding an overlay div ...

On smaller screens, the top placement of right sidebar links is necessary

Our website layout is organized into 3 main sections: the top part contains the main menu, followed by the main content and a sidebar specific to each page. The main content and sidebar are structured using bootstrap col-* classes. On small screens, I en ...

How can JQuery detect input in the fields?

I have the following HTML code and I am looking to trigger a function based on the input in any of the input fields, regardless of the field number. <input type="text" pattern="[0-9]*" name="code" maxlength="1" au ...

picture located in the top corner of the page within the diva triangle shape

Is there a way to position my photo on the same level as a div and have it overlap slightly? <div id='triangle-topleft'> <img id="photo" src="photo.png"> </div> #triangle-topleft { width: 0; heigh ...

The floating label appears distorted when used with a datalist input in Bootstrap 5

How can I get the floating label to display correctly for datalists in Bootstrap 5? Currently, it looks like this... It's working fine without the form-floating class, but I want to use the floating form feature. <div class="form-floating" ...

How can I speed up the loading time of my background image?

I have noticed that my background image is loading slowly on my website. I expected it to be cached so that subsequent pages using the same background would load instantly. However, the background image is only loading once the entire page is drawn. My CS ...

Confirming class Value with Selenium IDE

I am looking to confirm the value of a specific class within an HTML code using Selenium IDE. Specifically, I want to retrieve the value of: data-val located under the class named tgl. In my example, this value can be either 0 or 1. How can I achieve thi ...

Adjusting the display property using the CSS plus symbol operator

I am currently in the process of designing a dropdown menu using CSS. The focus is on utilizing the following code snippet: #submenu_div { display: none; } #li_id:hover + #submenu_div { display: block; } UPDATE: Here is the corrected HTML structure ...

I'd love some clarity on the concept of stacking contexts

After encountering a bug with a non-clickable video player inside a jquery ui dialog, I resolved the issue by changing position:relative; to position:inherit; Other solutions included removing position:relative; altogether or adjusting the z-index of the ...