I have an element and when I want to hover over it. It shows the border as I want, but, what it does is that it scales the text and actually moves it...
Like so:-
BEFORE TRANSITION
AFTER TRANSITION
As you can see in the images the "About Us" moved left a bit after hovering and that's because of the border. How can I make it stay in its place? This is my code
&--dropdown {
list-style: none;
position: absolute;
width: 25rem;
height: 14rem;
background-color: $color-additional;
overflow: hidden;
&-item {
position: relative;
width: 34rem;
padding: 1rem 0 1rem 2rem;
transition: all ease 0.2s;
&:not(:first-of-type) {
border-top: 1px solid $color-navigation-border;
}
&:hover {
background-color: $color-white;
border-left: 5px solid $color-primary;
}
&-link {
color: $color-black;
text-decoration: none;
}
}
}
Don't use an outline
for this. Instead, lower the left padding by the amount the border adds.
li {
width: 300px;
padding: 20px 30px;
list-style: none;
background: yellow;
border-bottom: 1px solid black;
}
li:hover {
border-left: 5px solid red;
}
<li>Test</li>
<li>Test2</li>
This is how you have it right now. The padding-left
is 30px
and on :hover
the border-left
adds 5px
. So just subtract the border-left
width from the padding-left
width:
li {
width: 300px;
padding: 20px 30px;
list-style: none;
background: yellow;
border-bottom: 1px solid black;
}
li:hover {
border-left: 5px solid red;
padding-left: 25px;
}
<li>Test</li>
<li>Test2</li>
Since you provided some code now, just change it to this:
&--dropdown {
list-style: none;
position: absolute;
width: 25rem;
height: 14rem;
background-color: $color-additional;
overflow: hidden;
&-item {
position: relative;
width: 34rem;
padding: 1rem 0 1rem 2rem;
transition: all ease 0.2s;
&:not(:first-of-type) {
border-top: 1px solid $color-navigation-border;
}
&:hover {
background-color: $color-white;
border-left: 5px solid $color-primary;
padding-left: calc(2rem - 5px); //<-- I added this line of code
}
&-link {
color: $color-black;
text-decoration: none;
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments