CSS hover effect causes text to unexpectedly slide out before it is meant to

I've set up a collection of glyphicons that reveal expanding text when hovered over.

The problem I'm encountering is that if the text happens to be lengthy, it flashes over the container of the glyphicon before the CSS transition finishes.

You can see an example in this fiddle (focus on the second box when hovering).

I've been experimenting with different transitions and attempting to make the text appear only after the transition is complete.

Here's my HTML:

<div class="myContainer">
  <div id="myNav">
    <ul class="subMenu">
      <li class="listItem"><a href="#">List Item 1</a></li>
      <li class="listItem"><a href="#">List Item 2 with long text</a></li>
    </ul>
  </div>
</div>

And here's the CSS code:

.subMenu .listItem {
  clear:both;
  list-style: none;
  height:15px;
  width: 15px;
  color: transparent;
  cursor: pointer;
  float: right;
  background: #ededed url(https://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png) no-repeat 10px center;
  border: solid 1px #ccc;
  padding: 9px 12px 9px 10px;
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
}


.subMenu .listItem:hover {
  width: 100%;
  color: #000;
  cursor: auto;
  background: #fff
}


.subMenu .listItem a {
  color: transparent;
}

.subMenu .listItem:hover a{
  color: #000;
}

Answer №1

If you include overflow:hidden; in the .listItem class and prevent line breaks with white-space:nowrap; on the link, you can achieve the desired effect.

Check out the updated code on this new fiddle.

Here's the final version of the code:

#myNav {
  width: 50%;
}

.subMenu .listItem {
  clear:both;
  list-style: none;
  height:15px;
  width: 15px;
  color: transparent;
  cursor: pointer;
  float: right;
  background: #ededed url(https://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png) no-repeat 10px center;
  border: solid 1px #ccc;
  padding: 9px 12px 9px 10px;
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
  overflow: hidden;
}


.subMenu .listItem:hover {
  width: 100%;
  color: #000;
  cursor: auto;
  background: #fff
}


.subMenu .listItem a {
  color: transparent;
  white-space:nowrap;
}

.subMenu .listItem:hover a{
  color: #000;
}

I hope this solution is helpful for you! =D

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

Click to trigger image rotation with JavaScript

img { display: block; margin: 20px; width: 50px; height: 50px; } .crossRotate { -webkit-transition-duration: 1s; -moz-transition-duration: 1s; -o-transition-duration: 1s; transition-duration: 1s; -webkit-transition-property: -webkit-tran ...

What steps should be taken to switch a class from one li element to another and remove it in the process?

As I develop the navigation bar for my website, I am faced with a challenge. I want to create a button-like behavior where clicking on an li element triggers a drop-down section underneath it without using the # attribute to prevent jumping to the top of t ...

Error: Exceeded the maximum call stack size - What causes this and how can it be prevented?

I am currently utilizing standard JavaScript. As the title implies, I am encountering a RangeError and I'm unsure of how to prevent it. The issue at hand is that I shouldn't be receiving this error, and in reality, if I refresh the page there&ap ...

Learn how to include the srcObject attribute of a video tag and then dynamically inject it into an HTML page using JavaScript or jQuery

media stream object inside console and this is what I am seeing after setting the source attribute The following function is part of my client-side script. I am working on a project that involves WebRTC and this function is called whenever I need to add a ...

Seeking Assistance with Customizing HTML Uniform Panels

Looking at the HTML provided, I have two requirements: Request: I need to center the green boxes regardless of their height, without having to adjust the top:-10px/bottom:-10px values when the height changes. Eliminate the fixed top/bottom value (as the ...

How can I show a view page in a specific div element using CodeIgniter?

Here is how I'm implementing the dashboard view in my controller. My goal is to have a specific page, like the index page, displayed within a div element rather than opening in a new tab. public function index() { $this->load->view('in ...

reveal or conceal content on hover of mouse pointer

I am currently working on a section that functions like jQuery tabs, but instead of requiring a click to activate, I want it to work on mouse hover. The current implementation is somewhat buggy - when hovering over a specific section, it displays as expe ...

Modify the div's visibility based on selected option in the dropdown menu

In my PHP file, I have the following codes: <section id="placeOrder"> <h2>Place order</h2> Your details Customer Type: <select name="customerType"> <option value="">Customer Type?</option> <option value="ret ...

JavaScript's jQuery selector retrieves a child element from one location and adds it to a different

Why does the Jquery children selector select the img element, extract it, remove it, and then append it to another div element? Shouldn't it create a copy of the element being appended? var $anchors = $("#imageGallery a"); var $overlay = $('&l ...

Obtain the URL of the parent window from a modal dialog using JavaScript

What is the proper syntax for obtaining the URL (specifically, the PATH) of the parent window from a modal dialog box in Internet Explorer. I have attempted several variations such as: window.opener.document.location window.opener.location this.opener.do ...

set available date with angular bootstrap datetimepicker

Currently, I am utilizing an angular bootstrap datetimepicker plugin that can be found at https://github.com/dalelotts/angular-bootstrap-datetimepicker. My goal is to configure the calendar so that only dates within the range of today and seven days in t ...

The HTML form submission button fails to submit the form and instead just refreshes the page

I'm struggling to get the save button working on my Chrome Extension settings page. The .click() event doesn't seem to be activating at all. I've included my code below. Should I use the commented out button instead (see below)? HTML <! ...

Eliminate the table background effect on hover using HTML and CSS

If you need assistance with a contact form, please visit this link. There seems to be an issue with the hover effect on the fields causing them to turn dark grey. This may not align with your desired plain white background. You can view a screenshot https ...

Ways to regain control of the iframe window once a popup has been launched

I have a question regarding managing windows in Javascript. In my application, when I click on a link within an iframe, it opens a popup window where I enter my login credentials. After entering the credentials, I am able to close the popup window using a ...

JavaScript Bug Report

Currently, I am immersed in a project that encompasses various languages like HTML, JS, and PHP. While working on one of the PHP functions, I stumbled upon an unexpected anomaly. To dissect it better, I decided to break it down into simpler functions: &l ...

Can a small white pop-up be triggered by clicking a button?

While exploring the website , I noticed that clicking on Availability Zones opens a small window with text on the right side of the page. Is it possible to achieve a similar feature on a leaflet map without using JavaScript? This functionality would be tri ...

Utilize a unique font exclusively for Internet Explorer

I am encountering a significant issue trying to utilize custom fonts in Internet Explorer. Currently, I have implemented a specific font using @font-face and it works perfectly in modern browsers but fails to render properly in IE. The method I am curren ...

How can we transfer parameters in JavaScript?

My vision may be a bit vague, but I'll try to explain it as best as I can. I want to implement multiple buttons that can toggle the visibility of a div (I have this functionality working already). Each button should carry two values (a number and a l ...

Show the modal content in Bootstrap on mobile and tablet screens

I have exhaustively searched the web for a solution to my issue, but unfortunately, I have come up empty-handed. I am hoping that you can offer some guidance in this matter. I am currently utilizing modals to showcase details on my website. However, when ...

Ensure that the class is consistently assigned with identical col-md-* and col-lg-* properties across all instances

Bootstrap 5.2 is my framework of choice for targeting github pages, and here is a snippet of my code: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" ...