Stylish Interactive Menu Item

Having a fixed navigation at the bottom of my website has presented me with an issue. The hover effect, specifically the background slide, triggers before I even place my mouse over the text. Currently, the background slides up when my mouse enters the .item-container. My goal is to have the hover effect occur ONLY when my mouse is directly over the text and not any outside divs.

If you'd like to take a look, here is my jsFiddle: https://jsfiddle.net/tebrown/dLz8fL80/

<nav>
    <ul>
        <li>
            <a href="#">
                <div class="item-container">
                    <div class="item-top">The Song</div>
                    <div class="item-bottom-song-content">The Song</div>
                    <div class="item-bottom-song">Have a Listen</div>
                </div>
            </a>
        </li>
        <li>
        ...
    </ul>
</nav>

I would greatly appreciate any assistance with this matter.

Thank you!

Answer №1

Make this adjustment in your CSS:

.item-container {
    top: 150px;
    position: relative;
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    -webkit-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease;
    -o-transition: all 0.2s ease;
    transition: all 0.2s ease;
}
.item-container:hover {
    height: 225px;
    line-height: 300px;
    top: -210px;
}

The issue was that the initial height of the container was set to 225px, causing the item content to pop out when hovering over the bottom text.

To fix this, adjust the height of your .item-container so it is 30px when not hovered, and 225px when hovered to display its content properly.

Check out a working example on JSFiddle

Answer №2

While there are a few nesting/structural level issues present, make sure to correct them. However, I was able to get your code working based on what you provided. Take a look and see if it helps.

$('.item-top').find('span').hover(function(e) {


  $(this).parents('.item-container').css("top", "-225px");

  e.stopPropagation();


});

$('.item-container').mouseleave(function() {

  $(this).css("top", "0px");


});
html {
  font-size: 100%;
  /* 1 */
  -webkit-text-size-adjust: 100%;
  /* 2 */
  -ms-text-size-adjust: 100%;
  /* 2 */
}
...
</nav>

Answer №3

Many responses discuss positioning methods, but I'd like to introduce a unique approach using a different transition effect with a back-and-forth motion. Take a look at this fiddle example https://jsfiddle.net/dLz8fL80/3/

Explanation:

We have defined a transition for the .item-container:

.item-container {
    top: 0;
    position: relative;
    height: 225px;
    line-height: 300px;
    cursor: pointer;
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
}

And another transition for .item-container:hover:

.item-container:hover {
    top: -225px;
    -webkit-transition: all 0.2s ease-in-out 200ms;
    -moz-transition: all 0.2s ease-in-out 200ms;
    -o-transition: all 0.2s ease-in-out 200ms;
    transition: all 0.2s ease-in-out 200ms;
}

When your mouse enters the .item-container, it triggers the :hover effect, and when your mouse exits, the reverse effect occurs.

I've added a delay to the :hover action so that there is a smoother transition in and out without causing sudden movements during passing-by.

Answer №4

Make sure to properly nest UL and Li elements for easier styling. Avoid using div tags within list items. Example :

<ul>
    <li>
    <a href="#">The Song</a>
      <ul>
        <li class="item-bottom-song-content">The Song</li>
        <li class="item-bottom-song">Have a Listen</li>
      </ul>
    </li>

Answer №5

I'm not certain if this solution will be effective, but I have a suggestion:

nav ul li {
    width: 20%;
    float: left;
    text-align: center;
    line-height: 200px;
    color: #fff;
    text-transform: uppercase;
    font-size: 18px;
}

DEMO

Answer №6

To activate the hover effect, target the .item-top element instead of the .item-container. Alternatively, you could enclose the text in a <p> tag and apply the hover effect to p:hover.

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

"Customizing the properties of an Angular Material mat-slide-toggle: A step-by-step

<mat-slide-toggle>Slide Me!</mat-slide-toggle> https://i.stack.imgur.com/p1hzD.png https://i.stack.imgur.com/aCzs1.png Is it possible to customize the toggle-thumb-icon to increase its length and position it at the end of the bar? ...

Is it possible that the div's height is not being set to 0 pixels

<div style="height:0px;max-height:0px"> </div> It appears that setting the height of a div to 0 pixels is not having the desired effect. The div is still expanding to display its contents, so how can we stop this from occurring? ...

"Position the label on the left and input on the right for

Having trouble with label and input alignment - I've attempted: <div class="form-group"> <label class="control-label" for="" style="float: left;font-size: 20px;padding-right: 10px;">ID : </label> <input style= ...

Clicking within the text activates the dropdown menu, but clicking outside the text does not

My custom drop down menu is not functioning properly. When I click on the text, it successfully links to another place, but when I click beside the text, it does not link. Can you please help me identify what's wrong here? Your assistance would be gre ...

Unable to load the Universe 55 font using the @font-face rule

I recently encountered an issue with using a custom font (Universe 55 font) in html5. I downloaded the .ttf file, applied it with the @font-face rule, and tested it on various browsers including IE, Chrome, and mobile browsers. Unfortunately, the font does ...

Step-by-step guide to creating a border around text with a number included in between the lines

Is there a way to replicate the appearance of the image shown below using CSS, Bootstrap, or other client-side methods? ...

How to Choose a Radio Button from a Group using Selenium WebDriver and Java

My goal is to be able to choose a specific radio button from a set of radio buttons grouped by the name attribute: <div> <input type="radio" name="exampleInputRadio" id="optionRadio1" value="1"> <input type="radio" name="exampleInpu ...

The header text appears misaligned and is not centered as intended

I'm a beginner in react native and I'm currently working on navigation. The issue I'm facing is that the header text is not aligning to the center. I've attempted the following: static navigationOptions = { title: "Help", alignSelf: &a ...

Suggestions for preventing the highlighting of the space between buttons on a webpage

html: <button id='automoney' onclick='minusTen()'></button> <button id='automoney2' onclick='minusHundred()'></button> <button id='automoney3' onclick='minusFiveHundred()& ...

Is the Owl carousel Auto Play feature malfunctioning when hovered over?

I seem to be encountering an issue with the auto play functionality of the owl carousel. I have uploaded and included all the necessary files, and it is functioning properly when initially loaded. The auto play feature works perfectly, but when I hover ove ...

Python Application Engine - Streamlining Responses from HTML Control Arrays

In my attempt to use App Engine (Python), I am facing a challenge in sending POST values from a variable array of select controls within an HTML form. Each select control is associated with a text describing what the user is rating. For instance, let&apos ...

Retrieving a unique custom data-attribute using select2 on a <select> element

If you were presented with the following HTML5 snippet: <select id="example"> <option value="AA" data-id="143">AA</option> <option value="BB" data-id="344">BB</option> </select> $("#example").select2(); What i ...

What is the best way to place two radio buttons side by side in a row?

How can I place two radio buttons in a single row with their labels, like the example shown in the picture? ...

Unusual occurrence involving label span and the use of italic font styling

Currently following a Xamarin tutorial on creating a label view. You can check out the tutorial here. Encountered an issue where applying an italic font attribute to text within a span tag does not retain the text size set in the label tag. <StackLayo ...

Arrange pictures and div elements in a horizontal layout

I am facing an issue with my code that is displaying 5 'cards' in a messed up layout instead of a straight line. I have tried to align them vertically, but some are still higher and not in the right positions. For reference, I want the layout to ...

Exploring the world of CSS and designing layouts using multiple div elements

Upon reviewing this website, I must admit it is getting close to what I envision. However, being a perfectionist and new to HTML and CSS, I find myself struggling to achieve the desired outcome. The layout consists of two divs named topred and top yellow, ...

Use Bootstrap to effortlessly arrange columns horizontally in a row

I'm facing a scenario where I need to arrange the columns in a row horizontally. The challenge is to ensure that the row expands horizontally to fit the columns. I attempted to use white-space: nowrap on the row, remove floats on columns, and set the ...

Using PHP to access HTML content from a page that demands authentication

I need help developing a PHP script that can scrape data from an HTML page. Right now, it works perfectly with pages that don't require authentication. However, I'm struggling to figure out how to extract content from a page that requires users t ...

The Bootstrap carousel controls now add the carousel ID to the address bar instead of just moving to the next slide

I can't figure out why my carousel isn't working. The id of the carousel is showing up in the webpage's address, which usually happens when the 'bootstrap.js' file is missing, but I have included it. Can anyone help me troubleshoo ...

Eliminate custom CSS generated by themes on WordPress category pages

I am a newcomer to the world of Wordpress and I'm currently in the process of making adjustments to an existing theme. The theme itself is generating custom CSS code and adding it to the wp_head section. add_action('wp_head', 'custom_c ...