css width transition on hover over a link - html

i have a problem to use transition on a styled anchor.
it should expand to a higher width and show a glyphicon. i tried it width max-width but i think i miss something. the glyphicon works but not the "animated" width.
html:
<a class="link" href="/"> Order <a/>
css:
a.link {
background: #0069b4 none repeat scroll 0% 0%;
color: white;
font-size: 24px;
height: 60px;
cursor: pointer;
border-radius: 30px;
text-align: center;
padding: 10px 15px;
transition: max-width 1000ms ease-in-out;
-webkit-transition: max-width 1000ms ease-in-out;
-moz-transition: max-width 1000ms ease-in-out;
}
a.link:hover {
padding: 10px 40px;
max-width: 100%;
}
a.link:hover:after {
font-family: icomoon;
content: "\e903";
color: #ffffff;
font-size: 20px;
}
https://jsfiddle.net/Lg7kutpp/

Your code is not working, because it has no working width. It's changing size because of the padding, and therefore the transition:max-width will not work.
Easy way to fix with your code is to add transition:all.
Check this:
a.link {
background: #0069b4 none repeat scroll 0% 0%;
color: white;
font-size: 24px;
height: 60px;
cursor: pointer;
border-radius: 30px;
text-align: center;
padding: 10px 15px;
transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
}
a.link:hover {
padding: 10px 40px;
max-width: 100%;
}
a.link:hover:after {
font-family: icomoon;
content: "\e903";
color: #ffffff;
font-size: 20px;
}
<a class="link">Order></a>
I you just want to go with the transition only for the width property, you should add display:inline-block and a width property to the anchor class.
a.link {
background: #0069b4 none repeat scroll 0% 0%;
color: white;
font-size: 24px;
height: 60px;
cursor: pointer;
border-radius: 30px;
width: 100px;
display: inline-block;
text-align: center;
padding: 10px 15px;
transition: width 1s ease-in-out;
-webkit-transition: width 1s ease-in-out;
-moz-transition: width 1s ease-in-out;
}
a.link:hover {
padding: 10px 40px;
width: 150px;
}
a.link:hover:after {
font-family: icomoon;
content: "\e903";
color: #ffffff;
font-size: 20px;
}
<a class="link">Order</a>

a.link {
background: #0069b4 none repeat scroll 0% 0%;
color: white;
font-size: 24px;
height: 60px;
cursor: pointer;
border-radius: 30px;
text-align: center;
padding: 10px 15px;
}
a.link:hover {
padding: 10px 40px;
max-width: 100%;
transition: 1000ms ease-in-out;
-webkit-transition:1000ms ease-in-out;
-moz-transition:1000ms ease-in-out;
}
a.link:hover:after {
font-family: icomoon;
content: "\e903";
color: #ffffff;
font-size: 20px;
}
You should add the transition on the hover selector without max-width
https://jsfiddle.net/Lg7kutpp/1/

I believe you need to set max-width to something less than 100% in a.link.
What you're currently doing is setting max-width to 100% on hover, but the default setting of max-width is already 100%.
Either set max-width to something less than 100% under a.link, or set max-width to something greater than 100% under a.link:hover.
When it comes to the transition-property, you might as well write transition: all 1000ms ease-in-out rather than transition: max-width 1000ms ease-in-out, as using all will make sure that any animation on a.link will have the same properties.
Also, I'd recommend you don't use href="/" unless you intend to direct the user to the main page. If you just want an anchor that doesn't link anywhere, you can drop using href.
Hope this helps.

Related

transition css top and bottom

How can I make such animation ?
(https://i.stack.imgur.com/NTWjH.png)
please check link below
https://preview.themeforest.net/item/shopify-outstock-clean-minimal-drag-drop/full_screen_preview/21041667?_ga=2.52492833.847676305.1666954417-2031082058.1666954417
.wrap-img {
transition: all 200ms ease 0s;
-webkit-transition: all 200ms ease 0s;
-moz-transition: all 200ms ease 0s;
overflow: hidden;
margin: 0px auto;
position: relative;
background: #fff;
padding: 15px;
}
One option would be this:
.box {
/* Required for the position: absolute property of the overlay. */
position: relative;
}
/* Scroll up and down effect */
.scrolling {
background-size: cover !important;
width: 285px;
min-height: 500px;
border: 15px solid #fff; /* Border is white */
cursor: pointer;
transition: background-position 1.5s ease-out 0.5s
}
.scroll {
background: url("https://velatheme.com/demo/outstock/images/cosmetic2.jpg");
background-position: top center;
}
.scroll_top:hover {
background-position: bottom center !important;
transition: background-position 2s linear 0s;
}
/* Background separating the image and the button */
.overlay {
position: absolute;
display: flex;
justify-content: center;
align-items:center;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0,0,0,0.4);
}
.box:hover .overlay {
opacity: 1;
}
/* Button */
button {
display: none;
}
.box:hover button {
display: inline-block;
height: 48px;
width: 158px;
border: 4px solid #fff;
text-align: center;
line-height: 30px;
font-size: 14px;
font-weight: 600;
text-transform: uppercase;
color: #333;
}
.box button:hover {
display: inline-block;
color: #fff;
background: #333;
cursor: pointer
}
<div class="box scrolling scroll scroll_top">
<div class="overlay">
<button>VIEW DEMO</button>
</div>
</div>
To do the opposite effect, you would first have to change the classes to scroll_bottom and it would just change:
In .scroll :
background-position: bottom center;
And in .scroll_top:hover (In this case it would be .scroll_bottom:hover):
background-position: top center !important;

CSS's transition's ease-in-out doesn't seem to work

I have a simple overlay of text over an image, darkening the background in the process. I used transition with ease-in-out, but it doesn't seem to ease out properly.
I know that the ease-in-out should be applied to the thing itself, and not its pseudo of :hover, but it doesn't seem to want to work. I have tried many ways, moving it around, deleting stuff, adding stuff, but nothing seems to make sense.
I notice the text do ease out fine, but the background with rgba opacity doesn't co-operate. It just snaps back :(
Do refer to a live version at http://g4stly.com/staff.html to know what I'm talking about, specifically.
Thanks in advance!
My code is as follows:
#g4stly
{
background-image: url('http://g4stly.com/images/users/g4stly.jpg');
}
.textFrame
{
text-align: center;
font-size: 20px;
color: #DDAA49;
text-decoration: none;
background-repeat: no-repeat;
background-size: cover;
border-radius: 30%;
width: 250px;
height: 250px;
}
.textFrame p
{
opacity: 0;
height: 75%;
margin: 0;
border-radius: 30%;
transition: opacity 300ms ease-in-out;
}
.textFrame p a
{
text-decoration: none;
color: #976649;
font-size: 25px;
}
.textFrame:hover p
{
opacity: 1;
background: rgba(0,0,0,0.8);
}
.textFrame p:first-child
{
padding: 25% 0 0 0;
}
<div id="g4stly" class="textFrame textFrameLeft">
<p>g4stly<br><br>
Owner of everything g4stly related<br>
Basically, the boss.</p>
</div>
I noticed you updated the code. Looks like your issue has already been solved.
The .textFrame p was only applying transition for opacity, so you couldn't see the background transition. I seed you added background .... to the transition, you could also do:
transition: all 1000ms ease-in-out;
Another option would be to move the rgba background to inside the .textFrame p, so the background wouldn't suddenly disappear, fading out along with the rest of the element.
Hopefully this helps you understand the cause :)
You had a comma where there should have been a semicolon.
transition: background 1000ms ease-in-out;
#g4stly {
background-image: url('http://g4stly.com/images/users/g4stly.jpg');
}
.textFrame {
text-align: center;
font-size: 20px;
color: #DDAA49;
text-decoration: none;
background-repeat: no-repeat;
background-size: cover;
border-radius: 30%;
width: 250px;
height: 250px;
}
.textFrame p {
opacity: 0;
height: 75%;
margin: 0;
border-radius: 30%;
transition: background 1000ms ease-in-out;
transition: opacity 1000ms ease-in-out;
}
.textFrame p a {
text-decoration: none;
color: #976649;
font-size: 25px;
}
.textFrame:hover p {
opacity: 1;
background: rgba(0, 0, 0, 0.8);
}
.textFrame p:first-child {
padding: 25% 0 0 0;
}
<div id="g4stly" class="textFrame textFrameLeft">
<p>g4stly<br><br> Owner of everything g4stly related<br> Basically, the boss.</p>
</div>

CSS animation on mouse leave

So I'm trying to do something like tiles or what netflix does. I have a box that I am trying to make grow on mouse hover and reduce in size when the mouse leaves. So Far I have this.
.nav {
position: relative;
top: 25%;
width: 100%;
color: black;
text-align: center;
}
.nav a {
color: white;
text-decoration: none;
}
.link {
font-size: 24px;
width: 100%;
height: 25%;
background: linear-gradient(135deg, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
display: inline;
padding-right: 12.5%;
padding-left: 12.5%;
padding-bottom: 6.25%;
padding-top: 6.25%;
box-shadow: 0px 0px 10px 5px grey;
animation-name: downsize;
animation-duration: .5s;
animation-iteration-count: 1;
animation-direction: alternate;
animation-timing-function: ease-in-out;
}
.link:hover {
animation-name: resize;
animation-duration: .5s;
animation-iteration-count: 1;
animation-direction: alternate;
animation-timing-function: ease-in-out;
font-size: 32px;
padding-right: 14.5%;
padding-left: 14.5%;
padding-bottom: 8.25%;
padding-top: 8.25%;
}
<div class="nav">
<a href="/public/MM/EnterUp">
<div class="link" style="margin-right: 15px;">
Enter Up
</div>
</a>
<a href="/public/MM/EnterUp">
<div class="link" style="margin-right: 15px;">
View Ups
</div>
</a>
</div>
I used CSS-Tricks
to get it to reduce after the mouse hover. My problem is that unlike CSS-Tricks, when you load the page I don't want the downsize animation to run, just after the mouse leaves. Anyone have a solution? Thanks for the help!
While there is no equivalent of the mouseleave or mouseout events in CSS, you can achieve the same behaviour by applying the "exit" transition to the selector and then overriding it with the "enter" transition using the :hover pseudo-class, like so:
div{
background:#000;
color:#fff;
font-size:16px;
line-height:100px;
text-align:center;
transition:font-size .5s ease-out,line-height .5s ease-out,width .5s ease-out;
width:100px;
}
div:hover{
font-size:20px;
line-height:125px;
transition:font-size .25s ease-in,line-height .25s ease-in,width .25s ease-in;
width:125px;
}
/* HOUSEKEEPING */
*{box-sizing:border-box;font-family:sans-serif;margin:0;padding:0;}
body,html{height:100%;}
body{align-items:center;display:flex;justify-content:center;}
<div>Text</div>
Alternatively, if the transition you wish to apply is the same in both cases, only reversed then there is no need to override it in your :hover selector.
you can simply just use transition for the padding
something like this in your case should do it:
.nav {
position: relative;
top: 25%;
width: 100%;
color: black;
text-align: center;
}
.nav a {
color: white;
text-decoration: none;
}
.link {
font-size: 24px;
width: 100%;
height: 25%;
background: linear-gradient(135deg, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
display: inline;
padding-right: 12.5%;
padding-left: 12.5%;
padding-bottom: 6.25%;
padding-top: 6.25%;
box-shadow: 0px 0px 10px 5px grey;
transition: padding 0.4s ease-out;
}
.link:hover {
font-size: 32px;
padding-right: 14.5%;
padding-left: 14.5%;
padding-bottom: 8.25%;
padding-top: 8.25%;
}
The key here is the use of:
transition: padding 0.4s ease-out;

Text vertically & horizontally aligned on image on responsive Wordpress page

Here's the page upon which I'm working.
I'm using Shortcodes Ultimate to get the columns, and it's responsive. Now I'm trying to get a text hover with background over the images, preferably without JS for now. I can get it to hover perfectly if it's given defined height and width, but then that's not responsive.
On CodePen, it shows the title going all the way across the page, but the Shortcodes Ultimate columns eliminate that. But it probably isn't best design, either.
I've followed about 20 different tutorials to get where I am, but am stuck now.
CodePen
HTML:
<div id="portfolio_hover_wrapper">
<a href="#" class="wistia-popover">
<img src="https://embed-ssl.wistia.com/deliveries/b9d3c0914d895ac2fb274c0c8798ad66f6e5d4f0.jpg?image_crop_resized=640x360" alt="" class="hover" />
<span class="portfolio-hover-text"><span>ADO Rowing</span>
</a>
</div>
CSS:
#portfolio_hover_wrapper {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
#portfolio_hover_wrapper a {
display: inline-block;
width: 100%;
height: 100%;
position: relative;
}
span.portfolio-hover-text {
background: rgba(27,187,230,0.8);
color: white;
display: table;
font-size: 3em;
position: absolute;
width: 100%;
height: 100%;
top: 0;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
#portfolio_hover_wrapper a:hover span.portfolio-hover-text {
opacity: 1;
}
span.portfolio-hover-text span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
If I understand what you want try using top: 50%; transform: translateY(-50%); in .portfolio-hover-text.
My bad I misunderstood your question, try adding the following:
span.portfolio-hover-text {
background: rgba(27,187,230,0.8);
color: white;
display: block;
font-size: 3em;
position: absolute;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
span.portfolio-hover-text span{
position: absolute;
top: 50%;
transform: translate(-50%,-50%);
white-space: nowrap;
}
In order to overlay text over an image I like to set the parent DIV to have the image as a background and child the text to it like such
<div class="box image1">
<div class="overlay fade">
<span class="text">ADO Rowing</span>
</div>
</div>
CSS
.box {
width: 75%; /*To make it responsive*/
height: 40em;/*Height should be fixed*/
box-shadow: inset 0px 2px 7px 0 rgba(0, 0, 0, .6);/*just for looks*/
margin: 5% auto 0 auto; /*Centers the div*/
border-radius: 5px; /*just for looks*/
overflow: hidden; /*Needed if our text overflows*/
}
.image1 {
background: url(https://embed-ssl.wistia.com/deliveries/b9d3c0914d895ac2fb274c0c8798ad66f6e5d4f0.jpg?image_crop_resized=640x360);/*Image*/
background-size: cover;/*Makes the background look responsive*/
background-position:center;/*for looks*/
}
Now we need to style the overlay. More CSS
.overlay {
background: rgba(33, 150, 243, .6);/*Overlay color*/
text-align: center;
padding: 1em 0 1em 0;/*adjust this if you want it cover the entire img*/
height:25%;/*Change this to 100% for whole image*/
opacity: 0;
margin: 25% 0 0 0;/*Moves the banner down*/
box-shadow: 0 2px 7px rgba(33, 150, 243, .4);
}
.text {
font-family: Helvetica;
font-weight: 900;
color: rgba(255, 255, 255, .85);
font-size: 96px;
}
Padding will increase the div size and thus increase the color size, while margin will just space the div out without changing the size of the background, so I use margin to position and padding for sizing.
lastly we need to make some snappy animation on :hover
.fade {
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;
-ms-transition: opacity .25s ease;
transition: opacity .25s ease;
}
.box:hover .fade {
opacity:1;
}
That will change the opacity from 0 to 1 on hover with a .25s tranisition. That should be about it, hope that helps. View the CodePen Here

Amending Font Size Without Affecting Other Classes

Please see my code below:
HTML =>
<header>
<div class="menuWrap">
Home
About
AM
Work
Contact
</div>
</header>
CSS =>
header {
width: 100%;
height: 80px;
background-color: #F5F5F5;
border-bottom: 1px solid #E6E6E6;
}
.menuWrap {
margin: 0 auto;
width: 80%;
height: 100%;
text-align: center;
}
.menuItem {
line-height: 80px;
display: inline-block;
width: 20%;
color: #1DC0CE;
text-decoration: none;
font-family: 'Lobster', cursive;
font-size: 25px;
-o-transition: .2s;
-ms-transition: .2s;
-moz-transition: .2s;
-webkit-transition: .2s;
transition: .2s;
}
.logoItem {
line-height: 80px;
display: inline-block;
width: 15%;
background-color: #1DC0CE;
color: #FFFFFF;
text-decoration: none;
font-family: 'Lobster', cursive;
font-size: 25px;
border-bottom: 1px solid #1DC0CE;
-o-transition: .2s;
-ms-transition: .2s;
-moz-transition: .2s;
-webkit-transition: .2s;
transition: .2s;
}
When I am increasing the font-size for 'logoItem' the 'menuItem' elements position is moving (the text is moving down the page)
Any tips on how to stop this!?
Give them a uniform height and ensure it's large enough to work for both sizes:
#menuWrap a {
display:inline-block;
height:30px;
}
You should probably get rid of the line-height declaration as well.