Targeting specific property for transition delay - html

I am using the following CSS to animate features of a div. .shrink gets added to .header through Java
.brand, .brand:visited, .brand:hover {
display: block;
position: relative;
height: 100px; width: 100px;
margin-top: 25px;
background: url('img/logo.png') no-repeat center center;
background-size: contain;
border: 1px solid #fff;
border-radius: 50%;
-webkit-transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s ease;
-moz-transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s ease;
-ms-transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s ease;
-o-transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s ease;
transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s ease;
}
header.shrink .brand {
margin: 0; padding: 0;
height: 80px; width: 80px;
border-color: transparent;
}
I want to put a 0.35s delay on JUST the border-color transition. Not sure the proper notation so that it wont affect all values.
ALSO, is there a way to only have the delay applied in one direction? Meaning that I would like the delay to be applied when the border shows up, but no delay when it goes transparent.

Question 1 - How to add a delay of 0.35s only to border-color property transition?
It is very simple. Just add a delay in the last part of the comma separated values that is provided to the transition property (that is, the one for border-color) alone. In the shorthand when two time values are provided, the first would be considered as the duration and the second as the delay.
transition: height 0.35s ease,
width 0.35s ease,
margin 0.35s ease,
border-color 0.35s 0.35s ease; /* notice how the delay is added here alone */
Question 2 - How to add a delay only when border shows up (on hover)?
Again very simple, add two transition settings - one for the default selector and one for the :hover selector. In the one that is within :hover selector, add the delay because it applies when the border shows up and in the transition within the default selector do not provide any delay.
.brand {
display: block;
position: relative;
margin: 0;
padding: 0;
height: 80px;
width: 80px;
background: url('http://lorempixel.com/100/100') no-repeat center center;
background-size: contain;
border: 1px solid transparent;
border-radius: 50%;
transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s ease;
}
.brand:hover {
height: 100px;
width: 100px;
margin-top: 25px;
border: 1px solid #f00;
transition: height 0.35s ease, width 0.35s ease, margin 0.35s ease, border-color 0.35s 0.35s ease;
}
<div class='brand'></div>

Related

css transition not working in firefox properly

Basically I've an HTML 5 range element, which works as my app videos tracker.
Before mentioning my problem here is CSS stylesheet:
.vidskb_r::-moz-range-thumb,.vidskb_r::-webkit-slider-thumb{
height: 0px;
width: 0px;
appearance:none;
-moz-appearance:none;
-moz-transition: height .2s ease-in-out, width .2s ease-in-out;
-webkit-appearance:none;
transition: height .2s ease-in-out, width .2s ease-in-out;
-webkit-transition: height .2s ease-in-out, width .2s ease-in-out;
background-color:rgb(213,90,0);
}
input[type=range]:hover::-webkit-slider-thumb,input[type=range]:hover::-moz-range-thumb{
height:12px;
width:12px;
}
Now .vidskb_r::-moz-range-thumb,.vlrange::-moz-range-thumb, doesn't let me create my custom range thumb as long as I create a new specific class for my thumb:
.vidskb_r::-moz-range-thumb{
height: 0px;
width: 0px;
appearance:none;
-moz-appearance:none;
border-radius:50px;
background-color:rgb(213,90,0);
-moz-transition: height .2s ease-in-out, width .2s ease-in-out;
transition: height .2s ease-in-out, width .2s ease-in-out;
}
Reason: I don't know.
And Also the transition doesn't works too, when I hover over the range, it just pop up and not with animation.
Thanks in advance!

transition on link's 'hover-off' not animating

I have a button with a transition on hover
css
.main-nav li a {
position: relative;
display: inline-block;
padding: 12px 10px;
}
.main-nav li a:after {
content: "";
position: absolute;
display: inline-block;
background-color: #d11e5d;
margin: 0 auto;
height: 3px; width: 0;
bottom: 3px; left: 0; right: 0;
}
.main-nav li a:hover { color: #d11e5d; }
.main-nav li a:hover:after { width: 80%; }
/* other links */ .main-nav li a:hover, .main-nav li a:hover:after {
transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-webkit-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-moz-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-ms-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-o-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
}
html (generated from bootstrap/Wordpress)
<div class="main-nav">
<ul class="menu">
<li>
...
The after element animates in properly, but doesn't animate out (just stops abruptly)
The problem is that you are using the transition property in your :hover state.
Change this:
...other links... , .main-nav li a:hover, .main-nav li a:hover:after {
transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-webkit-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-moz-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-ms-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-o-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
}
To this:
...other links... , .main-nav li a, .main-nav li a:after {
-webkit-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-moz-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-ms-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-o-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
}
If you're wondering what is the difference between applying CSS transition property in hover rather than in its normal state, you can check this.
Notes:
Always make sure the property without vendor prefixes is placed
below the rest.
I see some issues in the last CSS block:
...other links... , .main-nav li a:hover, .main-nav li a:hover:after {
transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-webkit-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-moz-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-ms-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-o-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
}
As a minor fix, I'll point out that the vendor prefixed transition properties should always precede the "standardized" CSS property. In other words, order the unprefixed transition style to be last following those for -webkit-, -moz-, -ms- and -o-. See this response SO answer to prefix ordering.
I notice you include the .main-nav li a:hover:after CSS selector. If this is what you're using to try and effect a CSS transition when hovering off, it won't work. The :after pseudo-element is not for this usage. Rather, what you want is to apply the transition styles you declared on .main-nav li a. Notice I didn't include the :hover pseudo-element. That's intentional. This way, I'm saying "I want to transition these properties (width, background-color & border) when I DO hover onto the selected element". Then, apply the different width, background-color and border CSS styles on the .main-nav li a:hover element separately. These will be the property styles that get transitioned to once you hover over the link. You'll notice that when you hover over the link now, the styles transition as desired.
If you're also trying to apply a secondary transition when hovering off the link, you'll have to apply those styles separately for the .main-nav li a:hover selector. Additionally, you would then declare a transition property on the .main-nav li a:hover selector. As it stands now, you have the same transition being applied to both the .main-nav li a and .main-nav li a:hover selectors (which is technically fine, just maybe not what you wanted). See this post Different Transitions for Hover On/Off
.main-nav li a {
position: relative;
display: inline-block;
width: 25%;
font: bold 3rem/2 Fantasy, Arial, sans-serif;
padding: 12px 10px;
}
/* .main-nav li a:after {
content: "";
position: absolute;
display: inline-block;
background-color: #d11e5d;
margin: 0 auto;
height: 3px; width: 0;
bottom: 3px; left: 0; right: 0;
} */
.main-nav li a:hover {
width: 50%;
color: #d11e5d;
background-color: Yellow;
font: lighter 5rem/3 cursive, serif;
}
.main-nav li a:hover:after { width: 80%; }
/* ...other links */
.main-nav li a {
-webkit-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-moz-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-ms-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
-o-transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
transition: width 0.2s ease, color 0.35s ease, background-color 0.35s ease, border 0.35s ease;
}
.main-nav li a:hover {
-webkit-transition: font 0.2s linear;
-moz-transition: font 0.2s linear;
-ms-transition: font 0.2s linear;
-o-transition:font 0.2s linear;
transition: font 0.2s linear;
}
<!DOCTYPE>
<html>
<head>
</head>
<body>
<div class="main-nav">
<ul class="menu">
<li>
...
</li>
</ul>
</div>
</body>
</html>
Last, I'm assuming the ...other links text is intended as a comment. If so, that should be commented-out appropriately, /* Other links */, and can potentially cause issues.

Styling a Button with CSS - problems with the border

I have a button styled the following way:
button, .button {
-moz-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
-webkit-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
-ms-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
border-radius: 8px;
border: 0;
}
When I open it in Brackets Live Preview, all buttons have a grayish border. When I open this directly in Firefox, the buttons have no borders. I want the border to appear.
Why?
Manually specifying border: solid 1px causes the bottom border to disappear when hovering over the button, which looks ugly.
/edit: yes, I have a hover selector:
a {
-moz-transition: color 0.2s ease, border-bottom 0.2s ease;
-webkit-transition: color 0.2s ease, border-bottom 0.2s ease;
-ms-transition: color 0.2s ease, border-bottom 0.2s ease;
transition: color 0.2s ease, border-bottom 0.2s ease;
text-decoration: none;
border-bottom: dotted 1px;
color: inherit;
}
a:hover {
border-bottom-color: transparent;
}
The a selector is the right one, since the buttons are defined in the following way:
bar

Full hover animation duration with quick mouseover/mouseout?

I have a hovering effect on an image. If you mouseover it and stay there with the mouse, the transition will be execute with its given duration.
I have also done the correct transition when you leave the spot.
Now, i want that the hover transition starts with the given duration, no matter if you just hovered over the image for a quick 1millisecond.
Is this only possible with javascript?
.example { position: absolute;
left: 0;
height:320px;
bottom: 0;
width: 100%;
background: #000;
background-color: rgba(255, 255, 255, 0.4);
opacity:0;
-webkit-transition: background-color 2s ease-out;
-moz-transition: background-color 2s ease-out;
-o-transition: background-color 2s ease-out;
-ms-transition: background-color 2s ease-out;
transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-webkit-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
text-align: center;
line-height: 299px;
text-decoration: none;
color: #000000;
font-size:30pt;
}
.image:hover .example { background-color: rgba(255, 255, 255, 0.4);
-webkit-transition: background-color 0.5s ease-in-out;
-moz-transition: background-color 0.5s ease-in-out;
-o-transition: background-color 0.5s ease-in-out;
-ms-transition: background-color 0.5s ease-in-out;
transition: background-color 0.5s ease-in-out;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
opacity:1;
}
With this, if i hover over the image, my text and background colors animating in and when i leave the image the text and background color is animating out. It works okay. (even though, my above code is a bit unsorted for now)
So, all i want is that the fading in and out animation will be fully executed even if i just hover fast over the image and back.
I think it is not possible is it? (with css only i mean)
I am afraid, you would have to use a bit of Javascript because as far as I know, it is not possible to do it without javascript.
Add a class on hover, and remove it on animation end. Refer to this answer to know how to do that - css3 animation on :hover; force entire animation
PS: I would have put this is a comment, but I don't have the privileges right now.

CSS hover to stay on mouse over

Okay, so if you could go to;
http://jsfiddle.net/aled2305/UzM7U/4/
you will see a blue circle, when you take your mouse over a red square will appear to the right. Now that all works how I want, but I would like the red box to stay when the user then takes their mouse over it.
Now if you take your mouse over where the red square shows, it will show because of
.down:hover
{
opacity:100;
}
So is there a way to get the red square to stay when a mouse is over it, but only when it is activated by hovering over the blue circle.
Thanks in advance
Aled
UPDATE
Sorry forgot to say I would like the red square to hide once the mouse has been taken off.
Thanks
My demo will fade-in the square upon hovering the circle. From there, when you hover over the square, it will stay opaque. After you move off the circle or square, the square will fade-out.
The trick to getting this to work is setting 2 different transitions for the opacity, height, and width properties of the square, one for hover ON and one for hover OFF, as well as adding a delay attribute to the transition. The reason for transitioning height and width is that it will prevent you from being able to hover over the square without first hovering over the circle.
Here are the default settings of the square: opacity: 0, height: 0, and width: 0.
For the hover ON transition, you want opacity to fade-in over 1 second, but to be able to see that, the height and width values need to be 40px prior to the fade-in transition. To make that happen, you need to set a delay of 0 seconds on the height and width transitions. This way, the square is immediately at its max dimensions, which allows the fade-in transition to be seen.
The hover OFF transition will revert back to the default settings. What you want to have happen is for the opacity to ease-out over 1 second while at the same time keeping the values of height and width at 40px. Otherwise, height and width would instantly revert back 0 and you would not be able to see the fade-out transition. To make that happen you need to set a delay of 1 second on the height and width transitions. In doing that, the opacity eases out over 1 second and because of the 1 second delay on height and width, at that point, height and width will revert back 0.
See the jsFiddle demo
HTML
<div id="gravatar">
<div id="circle"></div>
<div id="square"></div>
</div>
CSS
#gravatar
{
float: left;
}
#circle
{
background-color: blue;
float: left;
height: 40px;
width: 40px;
border-radius: 20px;
}
#square
{
background-color: red;
float: left;
margin-left: 10px;
height: 0;
width: 0;
opacity: 0;
/* hover OFF */
-webkit-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
-moz-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
-o-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
-ms-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease;
}
#square:hover,
#circle:hover + #square
{
height: 40px;
width: 40px;
opacity: 1;
/* hover ON */
-webkit-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
-moz-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
-o-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
-ms-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
}
EDIT
The OP left a comment stating that adding contents to the square prevents the transitions from working correctly. I corrected it by adding overflow: hidden to the square.
I also added other styles to the CSS to account for the anchors the OP added.
See the jsFiddle demo
HTML
<div id="gravatar">
<div id="circle"></div>
<div id="square">
Profile Details
Account Details
</div>
</div>
CSS
#gravatar
{
float: left;
}
#circle
{
background-color: blue;
float: left;
height: 40px;
width: 40px;
border-radius: 20px;
}
#square
{
background-color: #2D3538;
float:left;
overflow: hidden;
margin-left: 10px;
height: 0;
width: 0;
opacity: 0;
/* hover OFF */
-webkit-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease;
-moz-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease;
-o-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease;
-ms-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease;
transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease;
}
#square > a
{
display: block;
font: 15px Verdana;
color: #FFF;
text-decoration: none;
height: 15px;
line-height: 15px;
margin: 10px;
}
#square > a:last-child
{
margin-top: 0;
}
#square > a:hover
{
text-decoration: underline;
}
#square:hover,
#circle:hover + #square
{
height: 60px;
width: 135px;
opacity: 1;
/* hover ON */
-webkit-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
-moz-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
-o-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
-ms-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease;
}
Here's a Fiddle Using JS that follows the following logic:
Red Box shows when hovering on Blue Circle
Red Box hides when mouse leaves Reds
You can get that effect by adding a little JQuery and modifying your CSS:
JQuery:
$(".gravatar").hover(
function () {
$(".down").addClass('hoverDown');
}
);
$(".down").mouseleave(
function () {
$(".down").removeClass('hoverDown');
}
);
Here's the CSS:
.gravatar {
background-color:blue;
float: left;
margin-top: 2px;
margin-right: 10px;
margin-left: 2px;
border-radius: 20px;
width: 40px;
height: 40px;
}
.down
{
float:left;
width: 40px;
height: 40px;
background-color:Red;
opacity:0;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
.hoverDown
{
opacity:1;
}
well for mouse in and mouse out action you can use the mousenter mouseleave jquery function
$(".gravatar").mouseenter(
function () {
$(".down").addClass('hoverDown');
}
);
$(".gravatar").mouseleave(
function () {
$(".down").removeClass('hoverDown');
}
);
working fiddle:
http://jsfiddle.net/UzM7U/9/