When hovering over, my text and image shift to the left in a strange and abnormal manner

Recently, I made a small code addition to an existing one in order to display text below an image and have the text highlighted in blue on mouse over. Everything seemed to be working fine until I noticed that on mouseover, the text and image shifted to the left side inexplicably. Can anyone offer some assistance?

<td align="right" valign="bottom" id="helpid">
<a href="javascript: void(null)" onClick="if(legendDIV.style.visibility=='visible') { legendDIV.style.visibility='hidden'; isClickonLegend = 1; } else { legendDIV.style.visibility='visible'; isClickonLegend = 1;}">


Help

I implemented a JavaScript function called highlightBG to turn the text color blue on mouse over. This was the only modification made to the existing tag.

Javascript Code :

function highlightBG(id,action) {   
    if(action==0)
    {
        document.getElementById(id).className='AttachOnMouseOverText';
    }
    else
    {
        document.getElementById(id).className='AttachOnMouseOutText';
    }
}

CSS Code:

.AttachOnMouseOverText{
    color: blue;        
    font-size: 9px;
    text-align: center;
}
.AttachOnMouseOutText{
    color: black;       
    font-size: 9px;
    text-align: center;     
}

Answer №1

It appears that part of the issue stems from adjusting the font size, causing inconsistencies in the display. Moreover, consider utilizing CSS selectors instead of relying solely on javascript for style modifications.

Below is an example:

<table>
    <tr>
    <td align="right" valign="bottom" id="helpid">
        <a href="javascript: void(null);" onClick="{...}">
        <img src="#ContactsImagePath#qmark_sm.gif" border="0" alt="Help">
        </a>
        <br>Help
    </td>
    </tr>
</table>

CSS:

#helpid {
    color: black;
    font-size: 9px;
    text-align: center;
}
#helpid:hover {
    color: blue;
}

This method allows you to establish a default appearance and make adjustments more efficiently by modifying a single attribute.

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

Having trouble pinpointing the issue with my JavaScript code

Recently, I've been experimenting with JavaScript code snippets and after making some edits to one particular sample, I can't seem to figure out why it's not working. Everything appears correct to me, but here is the code snippet (JSFiddle) ...

Tips for abbreviating HTML content using PHP

Similar Question: PHP: Truncate HTML, ignoring tags I have some HTML content stored in a database. I need to display this content in a shortened form. I attempted to use the mb_strstr function like so; $str = mb_strstr($this->htmlData, "</p> ...

Ways to handle the res.locals object in a request manipulation

I am currently utilizing node-restful in my project and I am looking to replace my date properties with the help of moment. However, when I attempt the following approach; var QuestionResource = app.user = restful.model('Question', questionSche ...

CSS with a "true" space for a fixed element (ensuring the previous element does not overlap with the current fixed element)

I am facing an issue with the layout of my webpage. I have two horizontal columns - the left one is fixed, along with a bottom footer that is below the second content column. When I add a border to the content column, it extends all the way down to the fo ...

I am attempting to create a stylish border for the .navbar-collapse element, but unfortunately, my efforts have been unsuccessful so far

I need assistance with adding a border around my mobile drop-down menu. I've tried using .navbar-collapse but it's not working. Any suggestions? Here is a sample image of the mobile size: https://i.sstatic.net/O9oA1.png Below is my code: < ...

What is the best way to combine Node.js MySQL tables into a JSON format and transfer the data to the client?

I'm looking for a way to retrieve MySQL related tables as JSON from NodeJS and send it back to the client. For example, let's say I have a 'students' table and a 'studentCountry' table. The 'students' table has a fie ...

Setting up scheduled MongoDB collection cleanup tasks within a Meteor application

After developing an app to streamline form submissions for my team, I encountered a problem during testing. Meteor would refresh the page randomly, causing loss of data entered in forms. To solve this, I devised a two-way data binding method by creating a ...

Images are not appearing correctly on Chrome browsers when using Windows operating system

img tags seem to have unusual margins in Chrome, Edge, and Opera browsers, while Firefox displays them correctly. Queries What is causing these margins specifically in Chrome? The Devtool does not detect any margin properties. Is there a straightforward s ...

SyntaxError was not caught and an unexpected token export occurred at line 2371 in the popper.js file

I'm a beginner with bootstrap and jquery, and I'm attempting to utilize the datatables feature for sorting. However, when I run my code, I encounter the following error in the console: uncaught SyntaxError: Unexpected token export at popper.js:2 ...

I'm having trouble getting my CSS opacity to smoothly transition back to its original state of .5 using setTimeout(). What could be

I recently started learning JS, Jquery, and CSS. My goal is to create a Simon Says style game. However, when I attempt to animate the computer to automatically light up the correct square, I faced some challenges. To address this issue, I decided to star ...

Ways to customize hover color of Bootstrap 5 Dropdown menu

I'm having trouble modifying the hover color for a dropdown menu using Bootstrap 5. I'm unsure of the correct method to achieve this. The desired outcome is as follows: However, at the moment it appears like this: Apologies for the oversight, h ...

Is there a way to configure json-server, when utilized as a module, to introduce delays in its responses

json-server provides a convenient way to introduce delays in responses through the command line: json-server --port 4000 --delay 1000 db.json However, when attempting to achieve the same delayed response using json-server as a module, the following code ...

Stop html text from overflowing container

I'm facing an issue with a Bootstrap container where the text inside is overflowing and not aligning properly. How can I ensure that the text stays within the container and doesn't cross over, instead just aligning at the bottom of the upper text ...

Ways to resolve the angular error "Encountering an unhandled exception: Unable to locate module 'typescript' "?

I'm encountering errors when running ng serve. I've attempted the following code as well, but I'm still facing the same error: npm install -g typescript https://i.sstatic.net/Gyi71.png Error displayed in text format D:\xampp\htd ...

Error: EPERM -4048 - the system is unable to perform the operation specified

Every time I attempt to install a package using npm install, I encounter an error message (usually referring to a different path). I have attempted running npm cache clean, restarting my computer, and checking for any processes that may be interfering with ...

How to smoothly rotate a three-dimensional object in Three.js until it reaches a predetermined angle

Recently, I delved into the world of Three.JS, only to encounter a puzzling roadblock. My goal is to create a drivable car controlled by the Arrow Keys. Thus far, I've managed to make it move forwards and backwards, with the wheels turning appropriate ...

Arrange the Textbox next to each other

I have a requirement to display dynamically created textboxes side by side instead of one below the other. <div class="wrap-login100 p-l-20 p-t-25"> <form class="form" name="add_name" id="add_name"&g ...

Saving the output of an AngularJS expression in an input field

Looking at the calculations below, I am currently evaluating an expression, {{ annualIncome * 4.5 }}, in one input and then re-evaluating the same expression in another input. Instead of saving the result and transferring it to the other input, I am repeat ...

Having trouble getting a background image to show up using node.js?

Hi there, I have a quick and simple question. I am attempting to include a div with a background-image in my *.ejs page file. <style> .signPage{ background-image: url("//back.jpg"); width: 98%; height: 98vh; top: ...

What are the steps to manually activate input validation in Angular 2?

Having two inputs is the scenario here: The first input undergoes custom validator application The second input has a dynamic and editable value utilized in the custom validator If the custom validator is applied on the first input, then focus shifts to ...