I have a line of uniform distance navigation items that looks like this:

The selected menu item is shown in bold italics. The designer wants the rest to become italics on hover. When this happens, it expands the text of this element, which pushes all the other elements, because they are displayed in a line with a fixed margin. I have to get rid of the boost.
What is the correct way to fix this behavior? I have a couple of ideas using javascript:
- Load the text into a div and set the width of each div to the width of the text.
- Download, take the positions of each of the menu items relative to the div, then set their positions to absolute with the resulting coordinates (this would be good, because they are always in the same absolute position within the navigation div).
Both of them seem a bit hacky, and this is a pretty simple problem, so I thought there should be an easier way.
I use jQuery if that matters.
Below is a pretty minimal HTML page that will reproduce the problem:
<head> <style type="text/css"> body { background: black; font-family: sans-serif; } a { margin: 0px 20px; font-size: 16px; color: white; text-decoration: none; } a:hover { font-weight: bold; font-style: italic; } </style> </head> <body> <a id="projectslink" href="#projects">Projects</a> <a id="innovationslink" href="#innovations">Innovations</a> <a id="newslink" href="#news">News</a> <a id="aboutlink" href="#about">About</a> <a id="contactlink" href="#contact">Contact</a> <a id="breathlink" href="#">Breath*</a> </body>
source share