CSS - Move from current position to new fixed position - html

I'm trying to put some buttons on my site, but I'm struggling with positioning some of the animated elements. See the example:
https://codepen.io/dev_loop/pen/MWKYoGJ
<div class="btn-container">
<button>
<span class="text">Hover1</span>
<div class="icon-container">
<div class="icon icon--left">
<svg>
<use xlink:href="#arrow-right"></use>
</svg>
</div>
<div class="icon icon--right">
<svg>
<use xlink:href="#arrow-right"></use>
</svg>
</div>
</div>
</button>
</div>
<div class="btn-container">
<button>
<span class="text">Hover2Test</span>
<div class="icon-container">
<div class="icon icon--left">
<svg>
<use xlink:href="#arrow-right"></use>
</svg>
</div>
<div class="icon icon--right">
<svg>
<use xlink:href="#arrow-right"></use>
</svg>
</div>
</div>
</button>
</div>
<svg style="display: none;">
<symbol id="arrow-right" viewBox="0 0 20 10">
<path d="M14.84 0l-1.08 1.06 3.3 3.2H0v1.49h17.05l-3.3 3.2L14.84 10 20 5l-5.16-5z"></path>
</symbol>
</svg>
<div class="support">
<i class="fab fa-twitter-square"></i>
<i class="fab fa-dribbble"></i>
</div>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100%;
height: 100vh;
display: flex;
overflow: hidden;
}
.btn-container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background: var(--bg);
&:nth-child(1) {
--btn-bg: #da0000;
--bg: #f22c3a;
}
&:nth-child(2) {
--btn-bg: #fac300;
--bg: #fc6100;
}
}
button {
--width: 180px;
--height: 60px;
border: 0;
position: relative;
min-width: var(--width);
min-height: var(--height);
border-radius: var(--height);
color: #fff;
font-family: "Montserrat";
font-weight: bold;
background: rgba(0, 0, 0, 0.3);
cursor: pointer;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
margin: 0 1rem;
.text,
.icon-container {
position: relative;
z-index: 2;
}
.icon-container {
--icon-size: 25px;
position: relative;
width: var(--icon-size);
height: var(--icon-size);
margin-left: 15px;
transition: transform 500ms ease;
.icon {
position: absolute;
left: 0;
top: 0;
width: var(--icon-size);
height: var(--icon-size);
transition: transform 500ms ease, opacity 250ms ease;
&--left {
transform: translateX(-200%);
opacity: 0;
}
svg {
width: 100%;
height: 100%;
fill: #fff;
}
}
}
&::after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: var(--btn-bg);
border-radius: var(--height);
z-index: 1;
transition: transform 500ms ease;
}
&:hover {
&::after {
transform: translateX(65%);
}
.icon-container {
transform: translateX(125%);
.icon {
&--left {
transform: translateX(0);
opacity: 1;
}
&--right {
transform: translateX(200%);
opacity: 0;
}
}
}
}
}
.support{
position: absolute;
right: 10px;
bottom: 10px;
padding: 10px;
display: flex;
a{
margin: 0 10px;
color: #fff;
font-size: 1.8rem;
backface-visibility: hidden;
transition: all 150ms ease;
&:hover{
transform: scale(1.1);
}
}
}
In the above, everything works perfectly until you change the text contained within the button itself. Doing this throws off the "hover" positioning of the SVG arrow element, since its parent containers position is decided by the text on the button and its a percentage based translateX.
I want to use this code across multiple buttons with different text on each button and I'm looking to implement something on the transition effects like:
"Move the SVG from whatever its current position is, to right:0; or so when hovered, so the arrow is essentially right aligned"
What I've ended up doing in my code, is creating two different containers for the SVG; One positioned relatively in the "left" position, and another positioned absolute with a right:18px property to "stick" it to the right hand side of the button. I've then animated the opacity and translateX to try and make it look like its following the wipe effect of the button, but it's not really working nicely and looks janky.
https://codepen.io/Delarado/pen/yLqOBRr
<div class="btn-container">
<button>
<span class="text">Reset</span>
<div class="icon-container icon-container--left">
<div class="icon">
<svg>
<use xlink:href="#arrow-right"></use>
</svg>
</div>
</div>
<div class="icon-container icon-container--right">
<div class="icon">
<svg>
<use xlink:href="#arrow-right"></use>
</svg>
</div>
</div>
</button>
</div>
<svg style="display: none;">
<symbol id="arrow-right" viewBox="0 0 20 10">
<path d="M14.84 0l-1.08 1.06 3.3 3.2H0v1.49h17.05l-3.3 3.2L14.84 10 20 5l-5.16-5z"></path>
</symbol>
</svg>
.btn-container {
width: 100%;
height: 100%;
margin: 1em 0;
display: flex;
justify-content: center;
align-items: center;
background: var(--bg);
--btn-bg: #ff9900;
}
button {
--width: 13em;
--height: 60px;
border: 0;
position: relative;
min-width: var(--width);
min-height: var(--height);
border-radius: var(--height);
color: #fff;
font-weight: bold;
font-size: 1.1rem;
background: #ff990075;
cursor: pointer;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
margin: 0 1rem;
border-color: #00000050;
border-width: 1px;
border-style: solid;
.text,
.icon-container {
position: relative;
z-index: 2;
}
.icon-container {
--icon-size: 25px;
position: relative;
width: var(--icon-size);
height: var(--icon-size);
margin-left: 10px;
transition: transform 500ms ease;
.icon {
position: absolute;
left: 0;
top: 0;
width: var(--icon-size);
height: var(--icon-size);
transition: transform 500ms ease, opacity 250ms ease;
svg {
width: 100%;
height: 100%;
fill: #fff;
}
}
&--right {
//transform: translateX(-200%);
display:none;
}
}
&::after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: var(--btn-bg);
border-radius: var(--height);
z-index: 1;
transition: transform 500ms ease;
}
&:hover {
//The color of the text upon hovering
color: #000;
&::after {
//The position of the circle upon hovering
transform: translateX(73%);
}
.icon-container {
// //The position of the arrow upon hovering
// //transform: translateX(25%);
&--left {
opacity: 0;
animation: Arrowgo 500ms forwards;
}
&--right {
position: absolute;
right:18px;
display:unset;
animation: Arrowarrive 500ms forwards;
}
}
}
}
#keyframes Arrowgo {
from{
opacity:1;
transform: translateX(0);
}
to{
opacity:0;
transform:translateX(20px);
}
}
#keyframes Arrowarrive {
from{
opacity:0;
transform: translateX(-20px);
}
to{
opacity:1;
transform:translateX(0);
}
}
I also tried a single element with relative position, animated to absolute position on hover but that also looked awful. I can't figure out how to place it just to the right of the button text in a normal state, and then animate it from there over to the right hand side on hover.
I was wondering if anyone smarter than me had a nice elegant solution to this that avoids having a different class for each button to account for the different length text, whilst still maintaining a nice slick wipe effect on both the "secondary" button and the arrow SVG?
Thanks in advance!

Related

css click on image that covered with hover overlay

Hello so i made a gallery with images , and i added hover overlay to it, but also added lightbox, so now when i try to click on image i am clicking on overlay. how do i make it clickable trough hover layer that i made ?
.gallery-image{
position: relative;
width: 300px;
box-shadow: rgb(139, 9, 9) 0px 5px 10px;
}
.image-img{
width: 100%;
display: block;
}
.overlay{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: var(--tect-onblack);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0;
transition: all .4s ease;
}
.image-title i{
font-size: 70px;
}
.overlay:hover{
opacity: 1;
transition: all .4s ease;
cursor: pointer;
}
.overlay >*{
transform: translateY(30px);
transition: all .4s ease;
}
.overlay:hover >*{
transform: translateY(0);
}
<div class="gallery">
<div class="gallery-image">
<a href="./images/111.jpg" data-lightbox="shkaf" data-title="gal1">
<img class="image-img" src="./images/111.jpg"></a>
<div class="overlay">
<div class="image-title">
<i class='bx bx-zoom-in'></i>
</div>
</div>
<div class="price">
<p>120 000р</p>
</div>
</div>
Here's what I added/changed to achieve the desired effect (pure CSS alterations):
Moved the hover to .gallery .gallery-image and made it display: inline-block. This is so that overlay can still change, but its visual state is not tied to an event. Making it inline-block limits the hover area to the width of the content.
Added pointer-events: none to .overlay, so that mouse clicks will pass through it.
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, auto));
gap: 2rem;
align-items: center;
justify-content: space-evenly;
max-width: 1920px;
margin: 4rem auto 0 auto;
}
.gallery-image {
position: relative;
width: 300px;
box-shadow: rgb(139, 9, 9) 0px 5px 10px;
}
.image-img {
width: 100%;
display: block;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: var(--tect-onblack);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0;
transition: all .4s ease;
pointer-events: none;
}
.image-title i {
font-size: 70px;
}
.gallery-image:hover .overlay {
opacity: 1;
transition: all .4s ease;
cursor: pointer;
}
.overlay>* {
transform: translateY(30px);
transition: all .4s ease;
}
.overlay:hover>* {
transform: translateY(0);
}
<div class="gallery">
<div class="gallery-image">
<a href="./images/111.jpg" data-lightbox="shkaf" data-title="gal1">
<img class="image-img" src="./images/111.jpg"></a>
<div class="overlay">
<div class="image-title">
<i class='bx bx-zoom-in'></i>
</div>
</div>
<div class="price">
<p>120 000р</p>
</div>
</div>
</div>
I used the current clicked class to create a click event.
let imgs = document.querySelectorAll('.overlay');
imgs.forEach((img) => {
img.addEventListener("click", () => {
console.log("Image was clicked");
});
});
.gallery-image {
position: relative;
width: 300px;
box-shadow: rgb(139, 9, 9) 0px 5px 10px;
}
.image-img {
width: 100%;
display: block;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
color: var(--tect-onblack);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0;
transition: all .4s ease;
}
.image-title i {
font-size: 70px;
}
.overlay:hover {
opacity: 1;
transition: all .4s ease;
cursor: pointer;
}
.overlay>* {
transform: translateY(30px);
transition: all .4s ease;
}
.overlay:hover>* {
transform: translateY(0);
}
<div class="gallery">
<div class="gallery-image">
<a href="./images/111.jpg" data-lightbox="shkaf" data-title="gal1">
<img class="image-img" src="./images/111.jpg"></a>
<div class="overlay">
<div class="image-title">
<i class='bx bx-zoom-in'></i>
</div>
</div>
<div class="price">
<p>120 000р</p>
</div>
</div>

Html and CSS how to make image with hover effect a hyperlink

Hi so I'm quite new to programming and I have a basic knowledge in html and an even more basic knowledge of CSS. I've been trying to make images for my wordpress.com website that when hovered over by the cursor change to an overlay with text. I've managed to find some samples for what I want and I've gotten pretty close. The only thing I don't know how to do is make it so my image is also a hyperlink because currently all it has is the hover effect.
Here is my CSS code:
.container {
position: relative;
width: 400px;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.projeto01 {
color: white;
font-size: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
Here is my html code:
<div class="grid-portefolio">
<div class="container">
<img src="https://insert1australia.files.wordpress.com/2021/04/real-sinister-minister-14-250x250-1-1.png" class="image" alt="Albert Lee Banks Electorate"/>
<div class="overlay">
<div class="projeto01">Albert Lee<br>Banks Electorate</div>
</div>
</div>
So to summarize I want to know what to add to my code in either CSS or html to make it so the image also acts as a hyperlink to another page.
Just wrap everything inside an <a> tag, like this:
<div class="container">
<a href="https://example.com/"><img src="https://insert1australia.files.wordpress.com/2021/04/real-sinister-minister-14-250x250-1-1.png" class="image" alt="Albert Lee Banks Electorate"/>
<span class="overlay">
<span class="projeto01">Albert Lee<br>Banks Electorate</span>
</span>
</a>
</div>
I think it can help you.
.page-link {
position: relative;
width: 400px;
display: flex;
overflow: hidden;
}
.page-link img {
width: 100%!important;
height: auto;
transform: scale(1);
transition: transform .4s ease;
}
.projeto01 {
color: white;
font-size: 40px;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 135, 186, .6);
opacity: 0;
transition: opacity .4s ease;
}
.page-link:hover {
cursor: pointer;
}
.page-link:hover img {
transform: scale(1.1);
}
.page-link:hover .projeto01 {
opacity: 1;
}
<div class="grid-portefolio">
<a class="page-link" href="https://www.example.com">
<img src="https://insert1australia.files.wordpress.com/2021/04/real-sinister-minister-14-250x250-1-1.png" alt="Albert Lee Banks Electorate"/>
<div class="projeto01">Albert Lee<br>Banks Electorate</div>
</a>

Let scroll to top button stick above footer/credits

$(document).ready(function(){
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > $(window).height()) {
$('#scroll-top').fadeIn(300);
$('#scroll-top').css('display', 'flex');
} else {
$('#scroll-top').fadeOut(300);
}
});
//Click event to scroll to top
$('#scroll-top').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
//If Cookie-container is visable add bottom value
if ($("#cookie-notification-container").is(':visible')){
$("#scroll-top").css('bottom', 80 + 'px');
} else {
$("#scroll-top").css('bottom', '20px');}
});
/* ======================================================
► SCROLL-TOP
====================================================== */
#scroll-top{
display: none;
justify-content: center;
align-items: center;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 99;
border: none;
outline: none;
background: -webkit-linear-gradient(45deg, #ff91a2 0%,#ffabb7 100%);
background: <?= $headerBackgroundColor; ?>;
color: #fff;
cursor: pointer;
border-radius: 100%;
font-size: 18px;
box-shadow: 0px 6px 10px -5px rgba(0, 0, 0, 0.2);
width: 50px;
height: 50px;
overflow: hidden;
}
#scroll-top::after{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.0);
border-radius: 100%;
z-index: -1;
transform: scale(0);
transform-origin: center;
transition: transform 0.25s, border-radius 0.25s, background 0.25s;
}
#scroll-top:hover::after{
transform: scale(1);
border-radius: 100%;
transform-origin: center;
background: rgba(255,255,255,0.15);
}
#scroll-top svg{
transform: translateY(0%);
opacity: 1;
animation: fade-up 0.4s ease-out;
animation-delay: 0.2s;
animation-fill-mode: backwards;
fill:#ffffff;
}
#keyframes fade-up{
0%{transform: translateY(80%); opacity:0 ;}
80%{opacity:1 ;}
100%{transform: translateY(0%); opacity:1 ;}
}
/* ======================================================
► CREDITS
====================================================== */
#credits-container{
background: #2D2C2B;
min-height: 60px;
width: 100%;
display: flex;
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
box-sizing: inherit;
}
#credits-container .wrapper #credits{
height: 100%;
width: 100%;
min-height: 60px;
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center;
padding: 20px;
}
#credits-container .wrapper #credits p{
color: rgba(255,255,255,0.6);
letter-spacing: 0.005em;
font-size: 0.95em;
line-height: 1.2;
display: block;
margin: 0em 0;
margin-block-start: 0em;
margin-block-end: 0em;
margin-inline-start: 0px;
margin-inline-end: 0px;
text-align:center;
}
#media only screen and (max-width: 960px) {
#credits-container .wrapper #credits p{
font-size: 0.90em;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="height: 2000px;">
<button id="scroll-top" onclick="topFunction()">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 460" width="15" height="15">
<path d="M782.45,357.08l-340-340a60.07,60.07,0,0,0-84.86,0l-340,340a60,60,0,0,0,84.86,84.86L400,144.35,697.59,441.94a60,60,0,0,0,84.86-84.86Z" transform="translate(0 0.49)"/>
</svg>
</button>
</div>
<div id="credits-container">
<div class="wrapper">
<div id="credits">
<p>Created by Jhon Doh - ©<?= date("Y");?> Test Design.</p>
</div>
</div>
</div>
I have a scroll to top button that I would like to stick above the footer/credits (let it float 20 px above the credits/footer). When I apply sticky instead of fixed it does not work properly. I was wondering if someone could help me out. I am pretty new with this stuff. I have tried something similar with the cookie notification in the script(See below). But it is a bad temporary solution.

css transition works only one way

I've built a navmenu that has shown/hidden after click a button. In transition I change opasity .box navmenu and height .menu-box links.
But it works only when navmenu is shown. When I try to hide transition doesn't work, navmenu is hidden right away, without animation and time animation.
html
<div class="box " [ngClass]="{'show-mobile-navmenu' : showMobileNavmenu }">
<div class="menu-box" [ngClass]="{'show-menu-box' : showMobileNavmenu }">
<div class="menu " >
<div class="link" *ngFor="let link of links">
<modal-link [link]="link"></modal-link>
</div>
<div class="link">
<span class="a-link" (click)="changeLanguage()">{{'lang' | translate }}</span>
</div>
</div>
</div>
</div>
css
.link {
text-align: center;
}
.a-link {
font-size: 24px;
line-height: 48px;
width: 100%;
font-weight: bold;
}
.box {
background-color: #fff;
opacity: 0;
height: 0;
position: fixed;
left: 0;
width: 100%;
top: 69px;
z-index: 100;
overflow-y: auto;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE 10+ */
transition: opacity 0.5s ease-in-out;
}
.box::-webkit-scrollbar {
/* WebKit */
width: 0;
height: 0;
}
.box.show-mobile-navmenu {
height: calc(100vh - 69px);
opacity: 0.8;
}
.menu-box {
position: relative;
margin-top: -8px;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 400px;
opacity: 0;
transition: min-height .5s ease-out, opacity .5s ease-in;
}
.show-menu-box {
min-height: 100%;
opacity: 1;
}
.menu {
width: 100%;
padding-top: 38px;
padding-left: 3px;
}
How to do that when I hide navmenu opacity goes from 1 to 0 and links go down?

Possibility to change a font awesome icon with transition

No, I have no code to demonstrate but I have been wondering: Is it possible to change a font-awesome logo with just transition? Such as: Change the class? I did a little bit of research on w3schools and How can create transition effect in font awesome icon found this link aswell, but they didn't really help and this question has been with me for a long time.
so, the question is: Is it possible to make a logo change (font awesome) with css transition or do I need javascript for it?
in case the question shouldn't be posted here. please tell me where it should so I can move it.
Cheers,
Here you go:
This has been done here: https://codepen.io/toaster99/pen/BpgzQR
HTML:
<div id="container">
<div class="button">
<div class="icons">
<i class="fa fa-apple icon-default"></i>
<i class="fa fa-arrow-circle-down icon-hover"></i>
</div>
Download
</div>
</div>
CSS:
#attribution {
position: fixed;
right: 10px;
bottom: 10px;
color: #FE8989;
z-index: 100;
font-weight: bold;
cursor: pointer;
a {
color: inherit;
text-decoration: inherit;
}
}
#container {
background: linear-gradient(#8affff,#80eded);
position: relative;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.button {
position: relative;
margin-bottom: 40px;
display: inline-flex;
justify-content: center;
align-items: center;
background: #FE8989;
box-shadow: 0px 0px 0 0px rgba(0,0,0,0);
border-radius: 50px;
width: 25.25rem;
padding: 1rem 0;
font-family: 'Montserrat', sans-serif;
font-weight: 600;
font-size: 2.75rem;
color: white;
cursor: pointer;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
.icons {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 2.3rem 0 0;
width: 1.25rem;
height: 2.6rem;
i {
position: absolute;
top: 0;
left: 0;
display: block;
}
.icon-default {
transition: opacity .3s, transform .3s;
}
.icon-hover {
transition: opacity .3s, transform .3s;
transform: rotate(-180deg) scale(.5);
opacity: 0;
}
}
&:hover {
transform: scale(1.2);
box-shadow: 20px 15px rgba(0,0,0,0.15);
.icon-hover {
transform: rotate(0deg) scale(1);
opacity: 1;
}
.icon-default {
transform: rotate(180deg) scale(.5);
opacity: 0;
}
}
}
yes, its pretty simple after you see the solution but I was confused too which led me to this post.
css
#keyframes pulse {
0% {
color:transparent;
}
50% {
color: #065803;
}
75% {
color:rgb(113, 139, 0);
}
100% {
color: #065803;
}
0% {
color:rgb(189, 176, 1);
}
}
#linked{
font-size: 16.5rem;
color: white;
display: flex;
justify-content: center;
}
i{
animation: pulse 8s infinite ease;
} ```
HTML
<i id="linked" class="fab fa-linkedin"></i>
</a>
</div>
<div class="col-2-of-2">
<a href="projects.html" target="_blank">
<i id="linked" class="fas fa-code"></i>
</a>
```