There is a horizontal menu:
<ul>
<li>Text</li>
<li>Text 2</li>
</ul>
When User click over one the li becomes a font-weight bold. Therefore the width of element li is a bit changed. As result I got jumping menu.
How to fix it independent width of text?
4
Answers
you can use css to prevent changes in li width like:
this will prevent jumping
When you don’t adjust the
width
, when thewidth
is changed by other properties(font size
,style
, etc.), thewidth
will increase or decrecse as needed.You can set the
width
of theelement
to be fixed and You can usewidth: max-content
.Instead of directly applying font-weight: bold; to the li elements, you can use a trick to simulate the bold effect without changing the width.
Use
:before
pseudo-element withfont-weight: 700;
andcontent: attr(data-text);
: