This question already has answers here:
How to have multiple CSS transitions on an element?
(9 answers)
Closed 7 years ago.
I have a submit button in a form and I'm trying to make a simple on-hover transition. I want it to Swap the colors of the button's text and the button's background color. The way I have it right now, the text successfully transitions over time, but the background color is still switching colors instantly. How do I fix this to make the background color also change over time? I am using Google Chrome, so I only put in the -webkit-transition. Once I get this working I'll add the others for other browsers.
Here's my simplified code:
<form method="post" action="processRegistration.php">
<input class="submitbutton" type="submit" name="submit" value="Create Account" />
<form>
CSS:
#signupform
form
.submitbutton {
margin: 0 auto;
border-radius: 5px;
border: solid 2px #66cc66;
background-color: #66cc66;
color: white;
-webkit-transition: background-color 1s;
-webkit-transition: color 0.5s; }
#signupform
form
.submitbutton:hover {
background-color: white;
color: #66cc66;
-webkit-transition: background-color 1s;
-webkit-transition: color 0.5s; }
http://jsfiddle.net/ewkruuk3/
This is because you are declaring the transition twice. You are basically overriding the first transition with the second one. In CSS if there are two of the same rules, the last one applies. You have to seperate both by a comma in one declaration.
transtion: color .5s, background-color 1s;
Ideally though your css can be simplified to the following:
.submitbutton {
// Other rules
background-color: #66cc66;
color: white;
-webkit-transition: background-color 1s, color 0.5s;
transition: background-color 1s, color 0.5s; // Include this for browser compatability
&:hover {
background-color: white;
color: #66cc66;
}
}
You don't need a transition on :hover as the transition in the parent rule will also apply.
Related
I have a div that has a css animation transition for it's height when you hover over it. When you also hover over it, the background color change from pink to orange. However, I don't want this background color to change until after my height is done transitioning. Is there a way I can do this? I looked into using transition-delay but it seems that it can only be applied to one transition property? Thanks!
div {
margin: 3rem;
height: 10rem;
width: 10rem;
background: pink;
transition: height 0.3s ease;
}
div:hover {
height: 20rem;
background: orange;
}
<div />
You can specify delays for any property you like:
div {
transition: height 0.3s ease, background 0.3s ease 0.3s;
}
(In this case the last 0.3s defines the delay for the background color, see e.g. on MDN)
I know this type of question has been asked in some way shape or form on here but i cannot get this to work no matter what. Screenshot included as well the CSS. When you hover on the row, the left border highlights it. It's moving the link over 1px. I tried compensating with negative margin but no luck ( just to test it). It's only Firefox where this is happening.
%zebra-row {
transition: background-color .1s ease-out;
background-clip:padding-box;
&:nth-child(odd ) {
background-color: $alabaster;
}
&:hover {
background-color: $gallery;
border-left:2px solid $aqua-forest;
}
}
It is because the border is being applied and moving it over (as I'm sure you've assumed).
To get around this, you'll want to have a default border present but make it transparent. On the hover, you'll simply color the border.
%zebra-row {
transition: background-color .1s ease-out;
background-clip:padding-box;
border-left:2px solid transparent; /* Set the transparent border */
&:nth-child(odd ) {
background-color: $alabaster;
}
&:hover {
background-color: $gallery;
border-left-color:$aqua-forest; /* Color it on hover */
}
}
This prevents the "jump" you were talking about because the border is, essentially, always there.
Using CSS transitions on most properties runs as expected, except this issue I am having with colours.
I have set up a demonstration pen here.
When transitions are instructed to change the color property, they all queue after each other instead of happening all at once.
This seems limited to webkit as IE and Firefox work as expected.
#change {
color: green;
transition: color 200ms linear;
}
.changed {
color: red;
}
I think it's because color is inherited property, and you use * selector for transition. You should set transition: color only to element you change color, for example (http://codepen.io/sergdenisov/pen/QbjjjP):
#container {
padding: 0;
transition: color 500ms;
}
#container * {
transition: margin 500ms;
}
I have some css that gradually changes the background colour of an element when hovered on and the links below it.
It works perfect in Chrome and IE9+ but in FF it only works on the element you hover on and it instead immediately changes the colour on the elements below
EXAMPLE
I'm guessing the problem lies somewhere here:
.tree li {
float: left; text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
What do I need to change/add to get it to work properly in FF
Try setting the same transition on the element(s) below as well.
I'm guessing you want the lines in your example to have the same effect. I've updated the example with this JsFiddle.
Edit:
I added the transition CSS to all classes that handles the border you use to draw the lines
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
My blog simulates a terminal screen, so normal text is green and links are in red with a red background when the mouse is over. Since I use a monospaced font throughout the blog, <code> is styled to have a green background to differentiate from regular text. Likewise, <code> inside <a> has a red background that turns darker when the mouse is over. See this test page for a live version.
Here is the CSS (complete file here) for <a> tags:
a {
color:#CD0000;
text-decoration:none;
transition: background-color .6s;
-webkit-transition: background-color .6s; /* Safari and Chrome */
-moz-transition: background-color .6s; /* Firefox 4 */
-o-transition: background-color .6s; /* Opera */
}
a:hover {
background-color:#440000;
}
And for <code> tags inside <a> tags:
a code {
/* Only apply this to code that is a hyperlink */
color: #161616;
background-color: #CD0000;
border-radius: 5px;
padding: 0 2px 0px 2px;
text-decoration:none;
transition: background-color .6s;
-webkit-transition: background-color .6s; /* Safari and Chrome */
-moz-transition: background-color .6s; /* Firefox 4 */
-o-transition: background-color .6s; /* Opera */
}
a code:hover {
background-color:#440000;
border-radius: 5px;
padding: 0 2px 0px 2px;
}
The problem is that when I mouse over a link such as <a href='#'><code>long code</code></a>, the backgrounds of both the <code> and the <a> tags are transformed. Here are two images that illustrate this. In the first image, I managed to put the pointer of the mouse only over the <a> element. In the second, the mouse is over the <code> element:
Is there a way to style <code> links differently from normal links? Thank you in advance.
I think you're looking for the contains() selector, which is no longer part of the css3 selector spec
To achieve this, you will want to look at either a js framework solution, like has() in jquery or a dynamic css solution, such as less