My transition outs are not working, I am using the latest Chrome Browser and when I hover over the button, the transition in is working, however the transition out just cuts right off.
My CSS
.btn{
border-radius: 5px;
padding: 15px 25px;
font-size: 22px;
text-decoration: none;
margin: 20px;
color: #fff;
position: relative;
display: inline-block;
}
.btn:active{
transform: translate(0px, 5px);
-webkit-transform: translate(0px, 5px);
box-shadow: 0px 0px 0px 0px;
}
.blue{
background-color: #55acee;
box-shadow: 0px 5px 0px 0px #3C93D5;
}
.blue:hover{
background-color: #6FC6FF;
transition-duration: .02s;
display: inline-block;
}
}
HTML is on this JSFiddle.
You need to put the transition on the base state not the :hover then it will transition between all states.
.blue {
background-color: #55acee;
box-shadow: 0px 5px 0px 0px #3C93D5;
transition: background-color 0.2s ease-out;
}
.btn {
border-radius: 5px;
padding: 15px 25px;
font-size: 22px;
text-decoration: none;
margin: 20px;
color: #fff;
position: relative;
display: inline-block;
}
.btn:active {
transform: translate(0px, 5px);
-webkit-transform: translate(0px, 5px);
box-shadow: 0px 0px 0px 0px;
}
.blue {
background-color: #55acee;
box-shadow: 0px 5px 0px 0px #3C93D5;
transition: background-color 0.2s ease-out;
}
.blue:hover {
background-color: #6FC6FF;
display: inline-block;
}
<div id="buttons"> Blu
</div>
You are adding a transition to the :hover state, not to the actual element.
It's usually better to define a transition on the element itself, and then change properties to it's states, this way it understands that whatever the state change, it should transition from one to the other.
.btn{
transition: background-color 0.2s ease-out;
}
.btn:active{
...
}
.btn:hover{
...
}
Your just need to insert this on your btn main class
.btn{
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
Related
Hi I am trying to combine 2 hover effects. First hover effect takes places when you hover over the button, the other one is when you hover over the arrow. I am trying to combine those 2 hover effects to take place simultaneously. Could anyone please help me with that? Thank you so much
.btnMain {
padding: 15px 110px;
text-align: center;
transition: 0.5s;
background-size: 200% auto;
color: white;
box-shadow: 0 0 20px #eee;
border-radius: 10px;
font-weight: 600;
text-transform: uppercase;
letter-spacing:1px;
margin-top:40px;
font-size:16px;
display: inline-block;
border: 2px;
font-family: "Raleway", sans-serif;
cursor: pointer;
moz-transition: all .4s ease-in-out;
}
.btnMain:hover {
background-position: 100% 0;
color:#fff;
moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.gradient {
background-image: linear-gradient(to right, #25aae1, #4481eb, #04befe, #3f86ed);
box-shadow: 0 4px 15px 0 rgb(65 132 234 / 75%);
}
.arrowIntro {
color: black;
font-size:60px;
margin-left:-2%;
}
.arrowIntro::before {
display: inline-block;
padding-left: -8px;
content: "🠒";
transition: transform 0.3s ease-out;
position: relative;
top: 16px;
left: 3px;
}
.arrowIntro:hover {
color: black;
}
.arrowIntro:hover::before {
transform: translateX(12px);
}
Contact me<a id="arrowIntroId" href="#kontakt" class="arrowIntro"></a>
Please refer to CSS Transform Modules. Also, a technicality: You were trying to move the arrow on .arrowIntro:hover while you wanted it to move on .btnMain:hover
.btnMain {
padding: 15px 110px;
text-align: center;
transition: 0.5s;
background-size: 200% auto;
color: white;
box-shadow: 0 0 20px #eee;
border-radius: 10px;
font-weight: 600;
text-transform: uppercase;
letter-spacing:1px;
margin-top:40px;
font-size:16px;
display: inline-block;
border: 2px;
font-family: "Raleway", sans-serif;
cursor: pointer;
moz-transition: all .4s ease-in-out;
position: relative;
}
.btnMain:hover {
background-position: 100% 0;
color:#fff;
moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.gradient {
background-image: linear-gradient(to right, #25aae1, #4481eb, #04befe, #3f86ed);
box-shadow: 0 4px 15px 0 rgb(65 132 234 / 75%);
}
.arrowIntro {
margin-left:10px;
display:inline-block;
color: black;
position:absolute;
top:7px;
right:20px;
transition: transform 500ms ease-in-out 25ms;
}
.arrowIntro::before {
content: "→";
font-size:30px;
color: white;
}
.btnMain:hover .arrowIntro {
transform: translateX(12px);
color: red;
}
Contact me<div class="arrowIntro"></div>
You need to move the hover to the .btnMain element:
.btnMain:hover .arrowIntro {
color: black;
}
.btnMain:hover .arrowIntro::before {
transform: translateX(12px);
}
Also, you cannot have an a tag within another a tag. That's malformed HTML and the first a will close at the first closing a. I changed that to a span.
.btnMain {
padding: 15px 110px;
text-align: center;
transition: 0.5s;
background-size: 200% auto;
color: white;
box-shadow: 0 0 20px #eee;
border-radius: 10px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 40px;
font-size: 16px;
display: inline-block;
border: 2px;
font-family: "Raleway", sans-serif;
cursor: pointer;
-moz-transition: all .4s ease-in-out;
}
.btnMain:hover {
background-position: 100% 0;
color: #fff;
-moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.gradient {
background-image: linear-gradient(to right, #25aae1, #4481eb, #04befe, #3f86ed);
box-shadow: 0 4px 15px 0 rgb(65 132 234 / 75%);
}
.arrowIntro {
color: black;
margin-left: -2%;
}
.arrowIntro::before {
display: inline-block;
padding-left: -8px;
content: "🠒";
transition: transform 0.3s ease-out;
position: relative;
left: 4px;
}
.btnMain:hover .arrowIntro {
color: black;
}
.btnMain:hover .arrowIntro::before {
transform: translateX(12px);
}
Contact me<span id="arrowIntroId" class="arrowIntro"></span>
I'm working to build a button styling where when the user hovers over a button, the button moves up 2 pixels. I have that working with the following on hover:
`transform: translateY(-2px);`
The problem is, if you move your mouse right under the button, the button starts to move but and the button now bounces/jumps from normal to active causing button jumpies.
Any idea on how I can implement the button moving up 2 pixels on hover but without the jumpies when the mouse is near the edge of the button?
.ui.button {
outline: none;
height: 48px;
font-weight: 500;
font-size: 17px;
line-height: 20px;
padding-top: 12.5px;
padding-bottom: 12.5px;
color: #fff;
background: green;
border: 1.5px solid darkGreen;
box-shadow: 0 2px rgba(6,164,105,.25);
transition: transform .1s ease-in-out,box-shadow .1s ease-in-out,-webkit-transform .1s ease-in-out,-webkit-box-shadow .1s ease-in-out;
}
.ui.primary.button:hover {
transform: translateY(-2px);
background: green;
border-color: darkGreen;
box-shadow: 0 4px rgba(6,164,105,.25);
}
<button class="ui medium primary button button-icon-with-text " role="button" style="margin-bottom: 0px;">Primary Button</button>
Similarly to Temani Afif's anwser, I would use a pseudo-element that's 2px longer than the element, but switching the overflow from hidden to visible on hover.
.ui.button {
position:relative; overflow:hidden;
outline: none;
height: 48px;
font-weight: 500;
font-size: 17px;
line-height: 20px;
padding-top: 12.5px;
padding-bottom: 12.5px;
color: #fff;
background: green;
border: 1.5px solid darkGreen;
box-shadow: 0 2px rgba(6,164,105,.25);
transition: transform .1s ease-in-out,box-shadow .1s ease-in-out,-webkit-transform .1s ease-in-out,-webkit-box-shadow .1s ease-in-out;
}
.ui.primary.button::after{
content:"";
position:absolute;
top:0; left:0;
width:100%;
height:calc(100% + 3.5px); /* translate + bottom border height*/
}
.ui.primary.button:hover {
overflow:visible;
transform: translateY(-2px);
background: green;
border-color: darkGreen;
box-shadow: 0 4px rgba(6,164,105,.25);
}
<button class="ui medium primary button button-icon-with-text " role="button" style="margin-bottom: 0px;">Primary Button</button>
An idea is to use a pseudo-element that will cover the space under button after the translation and you will avoid this effect. So it's like you simply increase the total height of your element instead of translating it.
.ui.button {
position:relative;
outline: none;
height: 48px;
font-weight: 500;
font-size: 17px;
line-height: 20px;
padding-top: 12.5px;
padding-bottom: 12.5px;
color: #fff;
background: green;
border: 1.5px solid darkGreen;
box-shadow: 0 2px rgba(6,164,105,.25);
transition: transform .1s ease-in-out,box-shadow .1s ease-in-out,-webkit-transform .1s ease-in-out,-webkit-box-shadow .1s ease-in-out;
}
.ui.button:after {
content:"";
position:absolute;
bottom:0;
right:0;
left:0;
height:0;
}
.ui.primary.button:hover {
transform: translateY(-2px);
background: green;
border-color: darkGreen;
box-shadow: 0 4px rgba(6,164,105,.25);
}
.ui.primary.button:hover:after {
content:"";
height:2px;
bottom:-3.5px; /* Don't forget the border !*/
}
<button class="ui medium primary button button-icon-with-text " role="button" style="margin-bottom: 0px;">Primary Button</button>
Another idea is to use a container for the button on where you apply the hover. This will work with any value of transalation and you avoid doing calculation to find the values of the pseudo-element:
.ui.button {
position: relative;
outline: none;
height: 48px;
font-weight: 500;
font-size: 17px;
line-height: 20px;
padding-top: 12.5px;
padding-bottom: 12.5px;
color: #fff;
background: green;
border: 1.5px solid darkGreen;
box-shadow: 0 2px rgba(6, 164, 105, .25);
transition: transform .1s ease-in-out, box-shadow .1s ease-in-out, -webkit-transform .1s ease-in-out, -webkit-box-shadow .1s ease-in-out;
}
.contain {
display: inline-block;
}
.contain:hover .ui.primary.button {
transform: translateY(-2px);
background: green;
border-color: darkGreen;
box-shadow: 0 4px rgba(6, 164, 105, .25);
}
<div class="contain">
<button class="ui medium primary button button-icon-with-text " role="button" style="margin-bottom: 0px;">Primary Button</button>
</div>
I've tried many approaches to get this working correctly, but with no success.. I notice that this question has been asked a few times already, and i've tried the solutions i've found.. but with no success..
So i'll upfront say sorry if someone of you find this question as a duplicate :(
The hovered element is "food-box", and the element which needs the scale-animation is "food-box-image" :
<div class="food-box">
<div class="food-box-image" style="background-image: url(myimage.jpg);"></div>
... and i'm trying to get the animation working like this :
.food-box:hover ~ .foox-box-image {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
border:8px solid red;
}
but it will not fire :
the only way i got it working, is with specifying .food-box-image:hover, but then it will not fire when hovering the needed div element..
Here's complete code (which runs) :
Anyone know how to do this ?
.fixedbuttons-container {
position: absolute;
width: 100%;
}
.buttons,
.fixedbuttons {
display: flex;
flex-flow: row wrap;
}
.fixedbuttons > * {
width: 25%;
}
.fixedbuttons > * > * {
width: 100%;
text-align: center;
}
.food-box-container {
padding: 10px;
}
.food-box {
flex: 1;
position: relative;
background-color: white;
min-height: 300px;
background-color: #ffffff;
-webkit-box-shadow: 0px 0px 20px 4px rgba(0, 0, 0, 0.35);
-moz-box-shadow: 0px 0px 20px 4px rgba(0, 0, 0, 0.35);
box-shadow: 0px 0px 20px 4px rgba(0, 0, 0, 0.35);
border-color: #666666;
border: 1px solid #666666;
word-wrap: break-word;
margin: 0 !important;
padding: 0 !important;
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
}
.food-box:hover {
cursor: pointer;
-webkit-box-shadow: 0px 0px 20px 4px rgba(255, 255, 255, 0.35);
-moz-box-shadow: 0px 0px 20px 4px rgba(255, 255, 255, 0.35);
box-shadow: 0px 0px 20px 4px rgba(255, 255, 255, 0.35);
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
}
.food-box:hover ~ .foox-box-image {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
border:8px solid red;
}
.food-box .food-box-image {
position: absolute top: 0 left: 0;
background-size: cover;
width: 100%;
min-height: 150px;
background-color: #ffffff;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.food-box .food-box-content {
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
position: absolute bottom: 0 left: 0;
word-wrap: break-word;
width: 100%;
min-height: 150px;
background-color: #ffd531;
color: #000000;
font-size: 80%;
padding-top: 60px;
padding-left: 5px;
padding-right: 5px;
}
.food-box:hover > .food-box .food-box-content {
background: yellow !important;
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
}
.food-box .food-box-badge {
display: table;
background: #ffffff !important;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
line-height: 100px;
border-radius: 50%;
font-size: 12px;
color: #000000;
text-align: center;
-webkit-box-shadow: 0px 0px 39px 4px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 39px 4px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 39px 4px rgba(0, 0, 0, 0.75);
border-color: #d3e0e9;
border: 1px solid #b3c9e5;
padding-left: 10px;
padding-right: 10px;
}
.food-box .food-box-badge span {
color: #666;
display: table-cell;
vertical-align: middle;
line-height: 1.2em;
word-wrap: break-word;
}
<div class="fixedbuttons-container">
<div class="fixedbuttons">
<div>
<a>
<div class="food-box-container">
<div class="food-box">
<div class="food-box-image" style="background-image: url(https://assets.epicurious.com/photos/57c5c6d9cf9e9ad43de2d96e/master/pass/the-ultimate-hamburger.jpg);"></div>
<div class="food-box-badge"><span>Sydhavsmeny</span></div>
<div class="food-box-content">
adslkfjaølkfj
</div>
</div>
</div>
</a>
</div>
<div>
<a>
<div class="food-box-container">
<div class="food-box">
<div class="food-box-image scalable" style="background-image: url(https://assets.epicurious.com/photos/57c5c6d9cf9e9ad43de2d96e/master/pass/the-ultimate-hamburger.jpg);"></div>
<div class="food-box-badge"><span>Sydhavsmeny</span></div>
<div class="food-box-content">
adslkfjaølkfj
</div>
</div>
</div>
</a>
</div>
</div </div>
The first is the typo foox* to be replaced with .food-box:hover > .foox-box-image as pointed out by #panther
Now if you want to only scale within the container box apply overflow: hidden to the wrapping container which is food-box
Hope this is what you are expecting.
.fixedbuttons-container {
position: absolute;
width: 100%;
}
.buttons,
.fixedbuttons {
display: flex;
flex-flow: row wrap;
}
.fixedbuttons > * {
width: 25%;
}
.fixedbuttons > * > * {
width: 100%;
text-align: center;
}
.food-box-container {
padding: 10px;
}
.food-box {
overflow: hidden;
flex: 1;
position: relative;
background-color: white;
min-height: 300px;
background-color: #ffffff;
-webkit-box-shadow: 0px 0px 20px 4px rgba(0, 0, 0, 0.35);
-moz-box-shadow: 0px 0px 20px 4px rgba(0, 0, 0, 0.35);
box-shadow: 0px 0px 20px 4px rgba(0, 0, 0, 0.35);
border-color: #666666;
border: 1px solid #666666;
word-wrap: break-word;
margin: 0 !important;
padding: 0 !important;
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
}
.food-box:hover {
cursor: pointer;
-webkit-box-shadow: 0px 0px 20px 4px rgba(255, 255, 255, 0.35);
-moz-box-shadow: 0px 0px 20px 4px rgba(255, 255, 255, 0.35);
box-shadow: 0px 0px 20px 4px rgba(255, 255, 255, 0.35);
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
}
.food-box:hover > .food-box-image {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.food-box .food-box-image {
position: absolute top: 0 left: 0;
background-size: cover;
width: 100%;
min-height: 150px;
background-color: #ffffff;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.food-box .food-box-content {
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
position: absolute bottom: 0 left: 0;
word-wrap: break-word;
width: 100%;
min-height: 150px;
background-color: #ffd531;
color: #000000;
font-size: 80%;
padding-top: 60px;
padding-left: 5px;
padding-right: 5px;
}
.food-box:hover > .food-box .food-box-content {
background: yellow !important;
-moz-transition: all .1s ease-in;
-o-transition: all .1s ease-in;
-webkit-transition: all .1s ease-in;
transition: all .1s ease-in;
}
.food-box .food-box-badge {
display: table;
background: #ffffff !important;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
line-height: 100px;
border-radius: 50%;
font-size: 12px;
color: #000000;
text-align: center;
-webkit-box-shadow: 0px 0px 39px 4px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 39px 4px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 39px 4px rgba(0, 0, 0, 0.75);
border-color: #d3e0e9;
border: 1px solid #b3c9e5;
padding-left: 10px;
padding-right: 10px;
}
.food-box .food-box-badge span {
color: #666;
display: table-cell;
vertical-align: middle;
line-height: 1.2em;
word-wrap: break-word;
}
<div class="fixedbuttons-container">
<div class="fixedbuttons">
<div>
<a>
<div class="food-box-container">
<div class="food-box">
<div class="food-box-image" style="background-image: url(https://assets.epicurious.com/photos/57c5c6d9cf9e9ad43de2d96e/master/pass/the-ultimate-hamburger.jpg);"></div>
<div class="food-box-badge"><span>Sydhavsmeny</span></div>
<div class="food-box-content">
adslkfjaølkfj
</div>
</div>
</div>
</a>
</div>
<div>
<a>
<div class="food-box-container">
<div class="food-box">
<div class="food-box-image scalable" style="background-image: url(https://assets.epicurious.com/photos/57c5c6d9cf9e9ad43de2d96e/master/pass/the-ultimate-hamburger.jpg);"></div>
<div class="food-box-badge"><span>Sydhavsmeny</span></div>
<div class="food-box-content">
adslkfjaølkfj
</div>
</div>
</div>
</a>
</div>
</div </div>
hey guys i build here a nice hover effect on a profile card, but i would like to have the border that i have on the hover effect more inside the content. padding didnt worked for me, any clue how to fix it.
i have here a demo code of it on bootply
thats what im looking fore
.model-card {
display: inline-block;
position: relative;
margin: 0em 0.7em 1.4em 0.7em;
background-color: #fff;
transition: box-shadow .25s;
width: 15em;
padding: 0px;
box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.25);
-webkit-transition: transform 0.3s ease-out;
-moz-transition: transform 0.3s ease-out;
-o-transition: transform 0.3s ease-out;
}
span.hover-content {
background: rgba(135,211,183,0.7);
color: white;
border: 1px solid #fff;
cursor: pointer;
display: table;
padding: 10px;
height: 21em;
left: 0;
position: absolute;
top: 0;
width: 100%;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
Please try this css:
span.hover-content span {
border: 1px solid;
display: table-cell;
text-align: center;
vertical-align: middle;
}
Try to use box-shadow
span.hover-content span {
box-shadow: inset 1px 1px #777, 1px 1px #777;
display: table-cell;
text-align: center;
vertical-align: middle;
}
Shadows work properly on all elements, on IE and Firefox, but not for the button element in Chrome and Safari:
http://jsfiddle.net/q8xaa/
<button class="btn-test">
<span class="btn">test</span>
</button>
.btn-test {
background-color: transparent;
border: 0;
padding: 0px;
}
.btn-test:hover .btn {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.btn-test .btn {
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
-ms-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
-webkit-box-shadow: 4px 4px 0px #000;
-moz-box-shadow: 4px 4px 0px #000;
box-shadow: 4px 4px 0px #000;
background-color: #f00;
margin: 0px;
padding: 10px;
height: 40px;
display: inline-block;
}
button {
margin: 0;
padding: 0;
border: 0;
overflow: visible;
}
Any ideas on how to solve?
Example http://jsfiddle.net/H23Jy/1/
I tried forcing a zero CSS3 transformation as shown below
CSS
button span {
-webkit-transform: translate3d(0,0,0);
}
and the shadow seems to work fine also on Chrome 35.
But as you can see, in that way the button is not vertically aligned with the other buttons, so you could use -webkit-transform: translateY(-3px); instead
Result