Here is the code I've been using to style my side navigation, which has been working perfectly without any transitions.
SCSS Code and a functional JSFiddle
.side-nav{
position: fixed;
z-index: 100;
right: 0;
margin-top: 15vh;
ul {
list-style: none;
background: red;
border-style: solid;
border-right-style: none;
border-width: 3px;
border-color: blue;
@include border-radius(20px, 0, 20px, 0);
width: 1cm !important;
}
li {
position: relative;
display: block;
right: 0;
width: 1cm;
span {
white-space: pre;
&.short {
color: black;
display: block;
}
&.long {
display: none;
color: white;
}
}
&:hover {
right:200%;
width: 3cm;
@include border-radius(20px, 0, 20px, 0);
border-style: solid;
border-right-style: none;
border-width: 3px;
border-color: blue;
background: red;
margin: -3px 0;
span {
&.short {
display: none;
}
&.long {
display: block;
}
}
}
}
a {
position: relative;
display: block;
text-decoration: none;
padding: 10px 0;
text-align: center;
}
}
However, when I add transition code as shown in this updated JSFiddle, the height of the ul
fluctuates during interactions.
SCSS Code and JSFiddle showcasing the issue
.side-nav{
position: fixed;
z-index: 100;
right: 0;
margin-top: 15vh;
ul {
list-style: none;
background: red;
border-style: solid;
border-right-style: none;
border-width: 3px;
border-color: blue;
@include border-radius(20px, 0, 20px, 0);
width: 1cm !important;
}
li {
position: relative;
display: block;
right: 0;
width: 1cm;
@include transition(all 1s);
span {
white-space: pre;
&.short {
color: black;
display: block;
}
&.long {
display: none;
color: white;
}
}
&:hover {
@include transition(all 1s);
right:200%;
width: 3cm;
@include border-radius(20px, 0, 20px, 0);
border-style: solid;
border-right-style: none;
border-width: 3px;
border-color: blue;
background: red;
margin: -3px 0;
span {
&.short {
display: none;
}
&.long {
display: block;
}
}
}
}
a {
position: relative;
display: block;
text-decoration: none;
padding: 10px 0;
text-align: center;
}
}
The issue arises when adjusting borders to maintain consistency while preventing height changes. To align borders of top and bottom li
elements with that of ul
, a margin: -3px 0
line was added due to a border-width
of 3px
.
How can I ensure a smooth transition where both margins and borders remain consistent, thus keeping ul
height unchanged?