The hover effect is simultaneously impacting all of them, rather than each one individually

I have been searching tirelessly for the root of my issue but so far, I've come up empty-handed. It's possible that it's due to my lack of knowledge rather than any personal shortcomings.

Coding isn't my forte and after a long day, it's likely I may have missed something crucial. Here's a brief overview of what I'm attempting to achieve.

I want to create a list of 5 options, each with a block underneath that is revealed when hovered over (indicated by color).

The problem I'm facing is that all blocks are showing up on hover, which shouldn't be happening.

Below is an example of what I've put together:

HTML

<div id="nature">
<a class="sound">
    <h4>Forest</h4>

    <div class="preview" style="background:red;">
    </div>
</a>

<a class="sound">
    <h4>Storm</h4>

    <div class="preview"style="background:blue;" >
    </div>
</a>

<a class="sound">
    <h4>Winter</h4>

    <div class="preview"style="background:lightblue;" >
    </div>
</a>

<a class="sound">
    <h4>Dusk</h4>

    <div class="preview"style="background:pink;" >
    </div>
</a>

<a class="sound">
    <h4>Ocean</h4>

    <div class="preview"style="background:yellow;" >
    </div>
</a>

</div>

CSS

#nature {
    width: 100%;
    position: absolute;
    margin: 0;
    padding: 0;
    bottom: 0;
    left: 0;
}
.sound {
    margin: 0;
    padding: 0;
    width: 20%;
    height: 130px;
    display: inline-block;
    float: left;
    background: green;
    cursor: pointer;
    transition: .5s;
    -webkit-transition: .5s;
    margin-bottom: -50px;
}
.sound:hover {
    margin-bottom: 0;
}
.sound .preview {
    height: 50px;
    width: 100%;
    overflow: hidden;
    clear: both;
    margin: 50px 0 0 0;
}

JSFiddle

Answer №1

Simplest method:

#nature > a {
  position: relative;
}
.sound {
bottom:-50px;
}
.sound:hover {
bottom:0;
}

Example on JSFiddle: http://jsfiddle.net/u3ssV/

By the way, you can also contain your content in a container with overflow set to hidden.. or am I missing something here? :)

Answer №2

The :hover effect is being applied to the .sound class, which is used on all blocks. This means that when it triggers on one item, it affects the entire class and causes all blocks with that class to change.

Consider using id's (indicated by #idName in css) to handle each block individually. There might be a more efficient way to isolate the changes using classes that I am not familiar with.

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

HTML5 on its own versus the dynamic duo of jQuery Mobile and AngularJS

We are in the process of creating a versatile mobile app that will work on multiple platforms using HTML5, JavaScript, and CSS. Our design approach includes utilizing Bootstrap for a responsive user interface, and Cordova to package the application for bot ...

What is the best way to decrease the width of one of the four columns?

I trust all is well with you. I'm having trouble adjusting the width of one of my table data cells. In the image attached below, you'll notice that my + icon is the same size as the other columns. I'd like to make it much narrower and posit ...

Styling Tip: Aligning text to the baseline of a height-adjusted input field using CSS

As per the information from the Mozilla documentation, it states that I can align the text in an input field to the baseline if the element's display property is set to inline-block. I have made adjustments to the height of several input elements, bu ...

The Kendo Dropdownlist mysteriously disappears behind the PDFViewer when using Safari

Currently, I am immersed in a project based on the MVC framework and utilizing the Kendo DropDownList. An problem has arisen, which is visualized in the image below. Specifically, the items of the Kendo DropDownList are becoming obscured by the PDFViewer ...

Revamp and Enhance Your Layout Using Bootstrap Cards

I am working with a bootstrap card and trying to control the visibility of the .task__content part using CSS transforms. Specifically, I want to hide it with transform: scaleY(0) and reveal it on hover over the .task element. However, I am encountering a s ...

What is the method for reverting style properties back to their CSS defaults using Javascript?

The php-generated page contains multiple elements structured like this: <td class="defaultTDStyle" style="color:userDefinedCustomColor" id="myTDId"></td> There is a default style in place with additional styles ap ...

Exploring a one-dimensional nested array in order to make updates to the higher level nodes

I have a 1D nested array: nestedArr: [ { id: 1, parentId: null, taskCode: '12', taskName: 'Parent', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []}, { id: 2, parentId: 1, taskCo ...

Conflicting behavior between jQuery focus and blur functions and retrieving the 'variable' parameter via the $_GET method

There is a simple focus/blur functionality here. The default value shown in the 'Name of Venue' input field changes when the user clicks on it (focus) and then clicks away(blur). If there is no text entered, the default value reappears. Input fi ...

What is the best way to create a fully clickable navbar item for the Bootstrap dropdown feature?

I'm struggling to make a button in a navbar fully clickable for the dropdown to open. Even when I try adding margin instead of padding, it only makes things worse. Can someone help me figure out what mistake I'm making here? Essentially, my goal ...

What is the best way to align product cards side by side instead of stacking them on separate lines?

I am currently working on a mock-up website for a school project. For this project, I am developing a products page where I intend to showcase the items available for sale. Although I managed to successfully copy a template from w3schools, my challenge lie ...

Tips for positioning a div within a grid:

Looking for help with displaying news on your CMS page? You may have encountered an issue trying to show the title and content in two columns within a row. Here is some CSS code that might guide you in the right direction: *{ margin:0; padding:0; ...

How can I ensure that my content stays fixed at the bottom of a scrolling div in Material UI React?

I have developed a React JS component using Material UI that includes a chat input feature. However, I am facing an issue where the width of the chat input is always half the screen size on desktop or mobile devices. When I try to change the width to 100%, ...

What is the best way to store objects in files using Node.js?

As I manage my Node server, a question arises - what is the best way to convert objects into a serialized format and save them to a file? ...

Take out the username field from the registration form in Woocommerce

Is there a way to eliminate the username section from the registration form on woocommerce? I attempted to remove certain lines from the woocommerce/myaccount/login-form.php <?php if ('no' === get_option( 'woocommerce_registration_gene ...

choose the initial element within a class

Seeking a way to target the first element within each group of the same class? Consider the following scenario: <div class="group"> <div class="element"></div> <div class="element"></div> <div class="element"&g ...

Express-minify is having trouble loading the CSS file. If we remove a portion of the file, it should be able

After implementing the express-minify middleware, I encountered an issue with loading the attached CSS file. Even after validating the CSS using an online service, no errors were detected. I attempted to debug by gradually removing elements, and the prob ...

The click event in an Angular 6 loop is not being activated

When the Test is clicked, the function should be invoked. However, nothing happens when I click on it. Here is the HTML component code: <div class="row m-0 justify-content-between" *ngFor="let i of k[currentk]?.details | keys"> <div (click ...

Basic event listener function, functional in CodePen but not operating in Chrome web browser

I'm experiencing an issue where event listener functions are not working on my browser (Chrome), but they work fine on CodePen. I've been troubleshooting this for about 2 hours, and I'm seeking some insights. Can anyone help? CodePen Link: ...

Different sources for multiple iframes

Greetings everyone, I am facing an issue with multiple iframes on my page, each with a different src attribute. Despite specifying unique sources for each iframe, upon loading the page, they all seem to be loaded with the same src. <html><body&g ...

Leveraging node.js and express for incorporating custom stylesheets and scripts

I recently designed a webpage with the following elements at the beginning: <link href="./css/font-awesome.min.css" rel="stylesheet"> <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet ...