How To Shift Inline Elements When the text Bold On Hover Using Css

admin_img Posted By Bajarangi soft , Posted On 09-10-2020

When we will use a:hover pseudo-class to add a bold effect to the inline elements then we observe that whenever we hover over elements with the mouse, the elements to the right side of the mouse gets shifted to the right

Inline Elements

We can use the letter-spacing CSS property to fix this issue and make non-shifting inline elements. The letter-spacing is a CSS property that is used to increase or decrease the space between characters in a text. This CSS property can be used to prevent the shifting of the inline elements which get bold when we hover over them. Below is the working example of the problem and solution to it.

Syntax:
 .class_name { letter-spacing: value }
Example-1
<!DOCTYPE hyml>
<html>

<head>
    <style>
        li {
            list-style: none;
            display: inline;
        }

        .nav a {
            letter-spacing: 0.36px;
        }

        li a:link,
        li a:visited {
            text-decoration: none;
            color: #000;
        }

        li a:hover {
            text-decoration: none;
            font-weight: bold;
        }

        .nav li a:hover {
            text-decoration: none;
            font-weight: bold;
            letter-spacing: 0;
        }
    </style>
</head>

<body>
<h3>Before:</h3>
<ul>
    <li><a href="#">Bajarangi Soft 1</a></li>
    <li><a href="#">Bajarangi Soft 2</a></li>
    <li><a href="#">Bajarangi Soft 3</a></li>
</ul>
<h3>After:</h3>
<ul class="nav">
    <li><a href="#">Bajarangi Soft 4</a></li>
    <li><a href="#">GBajarangi Soft 5</a></li>
    <li><a href="#">Bajarangi Soft 6</a></li>
</ul>

<body>

</html>
Note :Place The Mouse over the Text

Related Post