Home > Web Front-end > CSS Tutorial > How to Prevent Element Shifting on Hover with a Border?

How to Prevent Element Shifting on Hover with a Border?

Susan Sarandon
Release: 2024-12-20 17:27:22
Original
942 people have browsed it

How to Prevent Element Shifting on Hover with a Border?

Hovering Border Causing Slight Element Adjustment

Problem:

An unordered list of anchors with a hover event adds a border, but the anchors to the left shift slightly when hovered due to an increase in width. How can you ensure absolute positioning?

Solution:

Adding a transparent border to the non-hover state can prevent the "jumpiness" when the hover border appears.

#homeheader a:visited, #homeheader a{
    border:1px solid transparent;
}
Copy after login

Explanation:

The transparent border allows the width of the anchor to remain consistent, so there's no shift in positioning when the hover border appears. Here's a JSFiddle demo:

http://jsfiddle.net/TEUhM/3/

The above is the detailed content of How to Prevent Element Shifting on Hover with a Border?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template