Weird CSS pseudo element scaling behavior - html

I have a pseudo element on an anchor tag with an animated scale transformation, to use as a background for the selected navigation link. This is inside a nav tag which has an animated scale transformation to show and hide it. When I open the nav the position and or scaling of at least one of the pseudo elements is wrong and it appears at the top of the nav during the transition. If I remove the transition from the nav or the pseudo element the problem disappears. The problem only occurs on the opening animation but not the closing one.
The following images show the opening transition:
nav and pseudo element css:
header.navbar nav {
display: inline-flex;
align-items: start;
z-index: 100;
position: fixed;
right: 0;
top: 4rem;
height: calc(100% - 4rem);
flex-direction: column;
width: auto;
background-color: $backgroundColorVariant;
padding: 1em 0;
transform: scaleX(0);
transition: transform $defaultAnimation;
transform-origin: right;
box-shadow: inset 0 25px 15px -26px $shadowColor;
}
header.navbar.open nav {
transform: scaleX(1);
}
a::after {
content: '';
width: 100%;
position: absolute;
left: 0;
transition: transform $defaultAnimation;
}
header.navbar nav a::after {
transform: scaleX(0);
bottom: 0;
height: 100%;
background-color: $backgroundColorTransparent;
transform-origin: left;
z-index: -1;
border-left: 0.5em solid $primaryColor;
}
header.navbar.open nav a:hover::after,
header.navbar.open nav li>a.router-link-active::after {
transform: scaleX(1);
}
Any ideas as to what might be going on are munch appreciated.

Related

Unable to get the transition on hover

I am creating a navbar and when I want to add hover effect over links its not working, I want to add transform property to the after element of links but its not working.
#navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
.link-list {
display: flex;
gap: 2rem;
}
.menu-link {
color: var(--white);
text-decoration: none;
position: relative;
}
.menu-link::after { /*this is for the bottom border line which is 25% in length*/
background: var(--white);
content: "";
width: 50%;
height: 2px;
position: absolute;
left: 25%;
bottom: -4px;
transform: scaleX(0); /*i am adding transform 0 */
transform-origin: center;
transition: transform 500ms ease;
}
.menu-link:hover .menu-link::after{ /* unable to get this effect on hover */
transform: scaleX(1);
}
Link lists
<section class="link-list">
About
Careers
Events
Products
Explore
</section>
The meaning of scale is size * argument.
scaleX(0) will *0 so your element will disappear.
scaleX(1) will *1 so your element won't change.
Use the number bigger than 1 or smaller than 1 to do it.
#navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
.link-list {
display: flex;
gap: 2rem;
}
.menu-link {
color: var(--white);
text-decoration: none;
position: relative;
}
.menu-link::after { /*this is for the bottom border line which is 25% in length*/
background: var(--white);
content: "";
width: 50%;
height: 2px;
position: absolute;
left: 25%;
bottom: -4px;
transform: scaleX(0); /*i am adding transform 0 */
transform-origin: center;
transition: transform 500ms ease;
}
.menu-link:hover .menu-link::after{ /* unable to get this effect on hover */
transform: scaleX(1);
}
"<section class="link-list">
<a href="#" class="menu-link">About</a
><a href="#" class="menu-link">Careers</a
><a href="#" class="menu-link">Events</a
><a href="#" class="menu-link">Products</a
>Explore
</section>"

How to make a pseudo-class underline swipe from bottom to top with CSS?

I'm a beginner at CSS for about a week.
And this is my first question on stack overflow.
Hope that I'm asking in the right way. I'm happy to receive any corrections.
The problem
I use pseudo-class to make an underline that grows thicker when hovered.
I want to have it swipe from bottom to top while it swipes from top to bottom.
How can I make it?
I did search for similar questions but end up with block elements (gradient etc).
Thanks a lot!
Here is my code on CodePen.
a {
text-decoration: none;
color: teal;
}
a {
display: inline-block;
position: relative;
}
a::after {
content: "";
display: block;
height: 0.1rem;
transform: rotate(0.5deg);
background-color: #20c997; /* teal */
opacity: 0.3;
transition: height 0.3s;
}
a:hover::after {
height: 0.5rem;
}
You just need your underline to be absolute positioned to the link bottom. Left and right offset should be set to 0 to grow up to the whole link width (or you can just set width: 100%;)
a {
text-decoration: none;
color: teal;
}
a {
display: inline-block;
position: relative;
}
a::after {
content: "";
display: block;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 0.1rem;
background-color: #20c997; /* teal */
opacity: 0.3;
transition: height 0.3s;
}
a:hover::after {
height: 0.5rem;
}
A link text with a animated underline

Overlay on website goes in front of all elements

I made a photo gallery (html + javaScript + CSS). It works very simple: by clicking on each thumbnail a lightbox appears with a preview and a caption. When it happens the rest of the page, except for the lightbox itself, is covered with low opacity overlay. It worked fine but right now when I open any lightbox the overlay goes over (in front of) the entire page and the lightbox appears also behind it. Everything is covered with semi-transparent black. I suspect it's the problem with z-index, yet I didn't change a single z-index value within the code at all. What else can it be? Where did I make a mistake?
The CSS for the lightbox and the overlay looks like so:
.lightbox {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
pointer-events: none;
transition: opacity 0.5s;
z-index: 10;
}
.lightbox.preload {
transition: none !important;
}
.lightbox.open {
opacity: 1;
pointer-events: auto;
}
.lightbox .close {
background-color: #52616b;
cursor: pointer;
color: #1e2022;
text-decoration: none;
display: inline-block;
font-size: 2em;
line-height: 1em;
text-align: center;
position: absolute;
top: -0.4em;
right: -0.4em;
width: 1em;
height: 1em;
border-radius: 50%;
}
/* overlay */
.lightbox .close::before {
background-color: rgba(0, 0, 0, 0.9);
content: "";
cursor: pointer;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
}
There is more code but the rest of it is just for styling of image, text and link elements and they are all displayed correctly. So the problem must be within the lines I quoted. I'll be grateful for help.

CSS border (':after') not expanding full width when the text is wrapped

I am trying to add and animate a line under a link using CCS but the positioning of the line (or, perhaps, its width) breaks when the text wraps.
Here is an illustration of what I am trying to achieve and what the problem is:
normal behavior:
breaking:
Here is the fiddle of the illustration: https://jsfiddle.net/b1zajhs5/. To make it break, just shrink the result panel until the text wraps.
This is the HTML used
<div class="centered">
<span class="effect-underline">Some Text That Has to Be Quite Long To Prove the Point</span>
</div>
And this is the SCSS:
.centered {
border: 1px solid #ccc;
width: 80%;
margin: 2rem auto;
padding: 1.5rem .5rem;
text-align:center;
}
a {
text-decoration: none;
}
.effect-underline {
position: relative;
&:after {
content: '';
border-bottom: 1px solid;
width: 100%;
height: 1em;
display: inline-block;
margin-top: 10px;
position: absolute;
left: 0;
opacity: 0;
transition: all 0.35s;
transform: scale(0, 1);
}
&:hover {
&:after {
opacity: 1;
transform: scale(1);
}
}
}
Do you know how the line can be expanded the match the full width of the link when the text is wrapped?
Add display: inline-block; to .effect-underline to make it go across when the text wraps.
.centered {
border: 1px solid #ccc;
width: 80%;
margin: 2rem auto;
padding: 1.5rem 0.5rem;
text-align: center;
}
a {
text-decoration: none;
}
.effect-underline {
display: inline-block;
position: relative;
}
.effect-underline:after {
content: "";
border-bottom: 1px solid;
width: 100%;
height: 1em;
display: inline-block;
margin-top: 10px;
position: absolute;
left: 0;
opacity: 0;
-webkit-transition: all 0.35s;
transition: all 0.35s;
-webkit-transform: scale(0, 1);
transform: scale(0, 1);
}
.effect-underline:hover:after {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
<div class="centered">
<span class="effect-underline">Some Text That Has to Be Quite Long To Prove the Point</span>
</div>
The reason why display: inline-block worked, was because a span, by default has a inline display. So, naturally, the line is going till the end of a text, and the end was on last sentence, that broke bellow.
giving it a display of inline-block, an element becomes like a block element, so the line goes till the end of a block, not the end of a sentence.

How to animate border transition expand with CSS?

I'm trying to create a CSS transition where the border-bottom of a href element expands on :hover to the width of the link.
What I could find is a CSS solution where the background width is animated:
http://jsfiddle.net/mfn5nefb/82/
But that's not what I want, because after click on a navigation tab I want to leave the border as is. So I'd have to directly animate the border, instead of the background.
<!-- assume the border-bottom is only applied to an active=clicked navigation tab -->
<h1 style="border-bottom: 3px solid green;">CSS IS AWESOME</h1>
h1 {
color: #666;
position: relative;
display: inline-block;
}
h1:after {
position: absolute;
left: 50%;
content: '';
height: 40px;
height: 5px;
background: #f00;
transition: all 0.5s linear;
width: 0;
bottom: 0;
}
h1:hover:after {
width: 270px;
margin-left: -135px;
}
Here you see the "active" link gets a green border. And on hover I'd like to animate the other tabs, but the border itself. Currently the background is animated, which appears above the border and thus looks misaligned.
You can still achieve this by using a pseudo-element (with background) and expand it on hover. All that is required is to set the value for the bottom property as the inverse of expected border-width and also set the height of the pseudo-element to be the same as the border-width.
h1 {
color: #666;
position: relative;
display: inline-block;
}
h1:after {
position: absolute;
left: 50%;
content: '';
height: 3px;
background: #f00;
transition: all 0.5s linear;
width: 0;
bottom: -3px;
}
h1:hover:after {
width: 100%;
left: 0px;
}
<!-- assume the border-bottom is only applied to an active=clicked navigation tab -->
<h1 style="border-bottom: 3px solid green;">Tab1</h1>
<h1>Tab2</h1>
Another way to achieve the same effect using the border property itself would be to use transform: scale like in the below snippet. Here the scaleX(0) makes the original width of the element as 0 and on hover it is transitioned to full width using scaleX(1). Since, default transform-origin is at 50% in X-axis, the border looks as though it is expanding from the center.
h1 {
color: #666;
position: relative;
display: inline-block;
}
h1:after {
position: absolute;
left: 0%;
top: 0%;
content: '';
height: 100%;
transition: all 0.5s linear;
width: 100%;
border-bottom: 3px solid red;
transform: scaleX(0);
}
h1:hover:after {
transform: scale(1);
}
<!-- assume the border-bottom is only applied to an active=clicked navigation tab -->
<h1 style="border-bottom: 3px solid green;">Tab1</h1>
<h1>Tab2</h1>