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. This is not a good user experience thus needs to be removed.
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:
<!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><ahref="#">GeeksforGeeks 1</a></li><li><ahref="#">GeeksforGeeks 2</a></li><li><ahref="#">GeeksforGeeks 3</a></li></ul><h3>After:</h3><ulclass="nav"><li><ahref="#">GeeksforGeeks 4</a></li><li><ahref="#">GeeksforGeeks 5</a></li><li><ahref="#">GeeksforGeeks 6</a></li></ul><body></html>chevron_rightfilter_none - Output:

Recommended Posts:
- How to write bold text using HTML ?
- What is the difference between display: inline and display: inline-block in CSS?
- What is the difference between inline-flex and inline-block in CSS?
- How to write a:hover in inline CSS?
- HTML | DOM Bold Object
- How to spin text on mouse hover using HTML and CSS?
- How to rotate a text 360 degrees on hover using HTML and CSS?
- How to Skew Text on Hover using HTML and CSS?
- How to Create Ghost Text Animation on Hover using HTML and CSS?
- Shrink Text on Hover using HTML and CSS
- How to Shake Text on hover using HTML and CSS?
- How to display paragraph elements as inline using CSS ?
- Text Animation with changing the color of the text using HTML & CSS
- How to create long shadow of text without using text-shadow in HTML and CSS ?
- CSS | border-inline-start-style Property
- CSS | margin-inline Property
- CSS | margin-inline-end Property
- CSS | margin-inline-start Property
- CSS | border-inline-style Property
- CSS | border-inline Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

