hover causing the table cell to act erratically

My table consists of three cells with widths of 30%, 40%, and 30% respectively. The table itself occupies 25% of its container, which can range from 1024px to 400px.

The first cell contains a button labeled GALLERY. Upon hovering over the cell, the text changes to "<" using jQuery.

The issue arises when the table is compressed (container smaller than 600px) and I hover over the GALLERY button. The width of the cell changes due to the text being replaced by "<", causing the mouseover area to shift and the cell to flicker between hover states.

The cell's width is fixed, there are no padding or margins, and overflow:hidden is applied.

Any suggestions on how to resolve this? The same problem occurs with the third cell as well.

This issue only seems to occur in Firefox.

Screenshots:

  • Normal:
  • Hover:

Edit:

jQuery

$('td.back').hover(
    function() {
        $(this).empty().html('<').addClass("hover");
    },
    function() {
        $(this).empty().html('GALLERY').removeClass("hover");
    });

HTML

<table id="toolbar" style="display:none;">
      <tr>
        <td class="back" onclick="<?php 
          if ($gallery_id == "2") echo "goToGallery(1);";
          else echo "goToIndex();";
          ?>">GALLERY
      </td>

CSS

#toolbar td {
font-family:'helvetica',sans-serif;
font-size:11px;
color:white;
text-align:center;
cursor:pointer;
overflow:hidden;
-webkit-font-smoothing:antialiased;
}

#toolbar td.back {
width:30%;
}

#toolbar td.back:hover {
color:#e61b23;
}

Answer №1

The reason for this inconsistency is due to the lack of a fixed width for the table, causing the td (and table) to resize when you alter the cell contents to "<". Essentially, your td is always 30% the width of the table, which fluctuates based on its content. Initially, it may be 30% of a 100px wide table, but then become 30% of a 40px wide table (hypothetical values). This constant change in width causes your content to shift back and forth. To resolve this issue, establish a fixed width for either the table or the td. Alternatively, placing a fixed width div inside the td can allow the cell to expand or contract without affecting the content layout.

Answer №2

My opinion aligns with bbird's perspective on the situation. To address this issue, I recommend incorporating the following CSS attribute into the table:

table-layout: fixed;

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

Expanding text area size dynamically in Nuxt3 using Tailwind CSS

Is there a way to expand the chat input field as more lines are entered? I want the textarea height to automatically increase up to a maximum of 500px, and adjust the height of .chat-footer accordingly. Below is a snippet of my code. <div v-if="ac ...

Step-by-step guide to create an impressive autocomplete search box with jQuery UI

I'm currently using jQuery UI for autocomplete in my search box. So here's the array that I am passing from the controller to the view, which contains the JS. public function suggest_channel(){ $this->load->library('mcurl&apo ...

Locating HTML snippets within a document

I am trying to extract all HTML <p>...</p> elements from a document. I have been attempting to use regular expressions (Regex) with the following pattern: Regex regex = new Regex(@"\<p\>([^\>]*)\</p\>" ...

What is the best way to display an alert when the button is clicked repeatedly?

Is it possible to keep displaying the alert every time we click the button, rather than just once after clicking it? I currently have an alert set to trigger when a button is clicked, but it disappears after 3 seconds. How can I make it show up again with ...

Using PHP variables in CSS styling

Let me explain the situation. In my index.php file, I have a class called 'rectangles' which includes properties for color and size. I defined a variable named $rectangle($rectangle=new rectangles('red',25);). Additionally, I include ...

Having issues with contenteditable functionality not functioning properly on elements that are dynamically generated

Creating an unordered list dynamically and adding items to it on a button click. Appending it to a section with contenteditable set to true, but encountering issues. The code snippet below demonstrates the process: // Create text input var categoryInput = ...

Finding the offsetWidth (or similar measurement) for a list item (LI) element

Can jQuery be used to determine the width of an element? alert($("#theList li:eq(0)").offsetWidth); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ol id="theList"> <li>The quick brown ...

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 ...

Resetting CSS animations using animation-delay

My aim is to animate a series of images on my landing page using Next.js and SCSS. The issue arises when I try to add dynamic animations that reset after each cycle. The delay in the animation causes the reset to also be delayed, which disrupts the flow. I ...

Utilizing Cookies within an HTML Page

My current code is functioning perfectly, accurately calculating the yearly income based on the input "textmoney." I have a link to a more advanced calculator for a precise prediction. My goal is to find a way for the website to retain the data input from ...

How to Use CSS to Copy a Style Path and Conceal an Element within an iFrame

My goal is to adjust a division by including a width element in its CSS properties. I have attempted to use Chrome and Firebug to copy the CSS path, but it seems that the result is incorrect. After inserting it into my style.css file, the division remains ...

How can ListSubheader in Material-UI be customized to match the style of iOS UITableView?

Here is the current appearance of my ListSubheader. https://i.stack.imgur.com/HAzTA.png Currently, it is just aligned to the left. However, the default header view in UITableView on iOS looks like this: https://i.stack.imgur.com/F9Amv.png It features ...

Display information in an HTML table using JQuery AJAX and JSON data

As a new member and beginner learner, I have encountered some issues while trying to execute a certain task. Despite looking at similar questions, I couldn't find a solution that worked for me. What I am attempting to do is query my database to retrie ...

Tips for effectively displaying HTML data from a database on a web browser

Storing html data in a database is a common practice for many web developers. The html data generated by a wysiwyg editor is typically simple and straightforward. Prior to storing the html data in the database, it is essential to run it through HTMLPurif ...

Display list items in HTML based on the length of an array

In my backend, I have a user-defined array of cars. If the user selects 3 cars, the array will contain 3 elements. I would like to display specific details of the cars in HTML elements within a list. The array is based on JavaScript. Here is an example of ...

Tips for halting click propagation in VueJS

My dilemma lies within a recursive list (tree) where each element contains a @click="sayHello(el.id)". The challenge arises due to the nested structure of the list, such as: list-element-0-01 ├──list-el-1-01 │ └──list-el-2-01 └──list ...

Display a loading spinner dialog using Jquerymobile until the page finishes loading

I am facing an issue with my app where I need to show a Loading dialog while sending data from the first page to the server. The goal is to display the Loading dialog until the send operation (posting to server) is complete and then proceed to page two. I ...

Syntax error in Ajax password recovery

Currently, I am facing a syntax error with a form that I recently converted from PHP to utilize Jquery/Ajax. My main goal is to test the functionality of the form to ensure it can successfully submit and reset passwords. The specific error message I keep ...

Using jQuery to save PHP form output into an Excel spreadsheet

I have a PHP-enabled form on my website for collecting Address details. Currently, the output is sent to my email inbox. However, I would like the output data to be saved in an external Excel file named "address.xls" using jQuery/JSON. The input fields of ...

Is the same-origin policy being breached?

Hello there, I've been encountering an issue with my jQuery AJAX Call to retrieve data from a self-hosted webservice on the same domain. The response always returns as 0, indicating a cross-domain problem, even though it shouldn't be occurring. ...