Unexpected animation in CSS [closed] - html

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am working on a static website and have some animations in CSS:
*
{
-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;
}
This is fine and everything and every page is animated in the same way except one of my HTML documents which also contains input elements and a textarea:
<form action="script/contact-form.php" method="post">
<b>Full name:</b><br/>
<input type="text" name="name" /><br/>
<b>Subject:</b><br>
<input type="text" name="subject" /><br/>
<b>E-mail:</b><br>
<input type="text" name="email" />
<br/><br/>
<b>Your comments:</b><br/>
<textarea name="comment"></textarea>
<br/><br/>
<input type="submit" value="Submit" />
</form>
For some reason the entire page is then animated (unlike the other pages, which are using the same stylesheet). I tried disabling this with:
form, input, textarea
{
-moz-transition: none;
-webkit-transition: none;
-o-transition: color 0 ease-in-out;
-ms-transition: color 0 ease-in-out;
transition: none;
}
but it doesn't seem to have any effect. Here is what it looks like: http://notrussian.de/stack/contact-us.html. Clicking on other pages without the form has different effects.
This is starting to drive me nuts and I really hope you guys could help me out.
Thanks in advance.

What is going wrong
You say :
For some reason the entire page is then animated
That's the expected behaviour when you use this code :
* {
-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;
}
The CSS selector * means that any CSS properties for that selector are applied to every element on your web page.
The value all for property transition means that every property of those elements that can be animated will be animated.
So, the combination of CSS selector * and CSS property transition: all means that every property that can be animated will be animated for every HTML element on your web page.
Solution 1 : Animate ONLY what you want to animate
You could do something like this :
/** Get rid of this code
* * {
* -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;
* }
*/
.animate, .animate * {
-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;
}
Then, in your HTML, add class=animate to every element you want to animate :
<ul class="animate">
...
</ul>
There are many alternative implementations, but this is one of the easiest ones. For the best approach, see "Additional improvements" herebelow.
Solution 2 : Disable animation for what you DON'T want to animate
This should work :
form, input, textarea {
-moz-transition: none;
-webkit-transition: none;
-o-transition: color 0 ease-in-out;
-ms-transition: color 0 ease-in-out;
transition: none;
}
You say you tried it, but I can't find it anywhere in your code when I go to the page you referenced. Anyway, make sure you put it BEHIND the * selector.
Additional improvements
For the sake of performance AND to prevent unexpected behavior, it's best to always set animation ONLY for those properties and those elements you really want to animate.
So, if you want to animate both the width and height of your div elements, you should do something like this :
div {
-moz-transition: width 2s, height 4s;
-webkit-transition: width 2s, height 4s;
-o-transition: width 2s, height 4s;
-ms-transition: width 2s, height 4s;
transition: width 2s, height 4s;
}
If you want to animate just the background of your #navigation li elements, you should do something like this :
#navigation li {
-moz-transition: background 1s ease-in-out;
-webkit-transition: background 1s ease-in-out;
-o-transition: background 1s ease-in-out;
-ms-transition: background 1s ease-in-out;
transition: background 1s ease-in-out;
}

Related

Multiple webkit transitions in one line

-webkit-transition: width 0.4s, height 0.4s;
-moz-transition: width 0.4s, height 0.4s;
-o-transition: width 0.4s, height 0.4s;
transition: width 0.4s, height 0.4s;
This effects the size of a div element when it is animated/moved, but I also have a requirement to adjust the opacity of it as well:
-webkit-transition: opacity 0.4s ease-out;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
transition: opacity 0.4s ease-in;
Do these go one after another in my style sheet or is there a way for me to combine them into one? Is there a best practice?
Just use a comma to separate the properties in order to combine them (like you yourself did in the first example)
-webkit-transition: width 0.4s, height 0.4s,opacity 0.4s ease-in;
transition: width 0.4s, height 0.4s,opacity 0.4s ease-in;
Codepen Demo
Just for completeness: the following is the formal syntax of the transition property from the spec:
Value: none | <single-transition-property> [ ‘,’
<single-transition-property> ]*
Which shows that multiple properties may be transitioned when separated by a comma.

i have issue in css with transition it can't move smoothly in menu bar?

i have issue in CSS it can't move smoothly in menu bar, the menu in this link can anyone help me thanks .
here is the link jsfiddle.
i try this but nothing work :
.div-move{
-webkit-transition: width 1s ease-in-out;
-moz-transition: width 1s ease-in-out;
-o-transition: width 1s ease-in-out;
transition: width 1s ease-in-out;
}
You can't transition to width:auto, but by using max-width is automatically with use the size of your text. Just make sure the :hover width is longer then the text you use so it will all appear. Also I suggest using a transition on both hover and regular classes so you also have a transition when you mouse off the menu. Try changing these classes:
.text-header-move{
max-width: 0px;
float: right;
overflow: hidden;
-webkit-transition: max-width 1s ease-in-out;
-moz-transition: max-width 1s ease-in-out;
-o-transition: max-width 1s ease-in-out;
transition: max-width 1s ease-in-out;
}
.notification-bar:hover .text-header-move{
max-width:400px;
-webkit-transition: max-width 1s ease-in-out;
-moz-transition: max-width 1s ease-in-out;
-o-transition: max-width 1s ease-in-out;
transition: max-width 1s ease-in-out;
}
You want to transform to an "auto" value that was one of the problems.
.notification-bar:hover .text-header-move{
width:auto;
}
Take a look at this fiddle:
http://jsfiddle.net/herrfischerhamburg/jok48kpz/2/
I updated the fiddle to work with a "max-width", i think this is the better solution for you than the fixed width.

CSS 3 Transition effect

I am working on CSS 3 transition effect for navigation menu.I want to have opacity effect for the submenu on hover of the menu.And Its working.
But the problem is that I want to show submenu on hover of menu item.But in my case with the following code, submenu is opacity effect works on hover of submenu as well.
#mega-menu-wrap-primary-2 #mega-menu-primary-2 > li.mega-menu-megamenu > ul.mega-sub-menu {opacity:0 !important;
display:inline !important;
transition: opacity 1s ease-in-out;
-webkit-transition:opacity 1s ease-in-out;
-moz-transition:opacity 1s ease-in-out;
-o-transition:opacity 1s ease-in-out;}
/*for transition*/
#mega-menu-wrap-primary-2 #mega-menu-primary-2 li {}
#mega-menu-wrap-primary-2 #mega-menu-primary-2 > li.mega-menu-item:hover > ul.mega-sub-menu {
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition:opacity 1s ease-in-out;
opacity:1 !important;}
NOTE: I am having submenu with 660px height.And also I am using wordpress.So I can't show you on JSFiddle.
What might be the issue here ?
Tell me if you have doubt related to this question.Thanks.

Trigger CSS animations by hovering over a seperate element

I'm attempting to create a small animation on an image (the image grows slightly) when a link is hovered over using only CSS3 animations.
The relevant snippets from my code
HTML:
<img id="enterimg" src="img.png" alt="" />
<a id="enterbutton" href="home.php">Enter</a>
CSS:
#enterimg {
width: 350px;
height: 350px;
-webkit-transition: width 1s ease-out, height 1s ease-out;
-moz-transition: width 1s ease-out, height 1s ease-out;
-o-transition: width 1s ease-out, height 1s ease-out;
transition: width 1s ease-out, height 1s ease-out;
}
a:hover ~ #enterimg{width:400px;height:400px;}
I'm sure the transitions themselves are correct, but none of the different "calls" (the last line of CSS) I've tried have worked.
(This is similar to a number of other questions, but I've looked through them and as far as I can tell none of them answer my question)
Thanks to Lokesh Suthar.
The order of the sibling selector required I placed the link first in the markup. Since the selection was written:
a:hover ~ #enterimg{width:400px;height:400px;}
The markup needed to be in that order
<a id="enterbutton" href="home.php">Enter</a>
<img id="enterimg" src="img.png" alt="" />
If you wrap the content in the trigger, then position the content absolutely, you can achieve something similar to triggering a sibbling with CSS. At least it'll look and act that way.
HTML
<a href="">Click Me
<img id="enterimg" src="http://www.druglessdrs.com/wp-content/uploads/2012/07/google-logo-small.jpg" alt="" />
</a>
CSS
a img {
display:block;
position:absolute;
top:80px;
left:0;
border:solid 1px black;
-webkit-transition: width 1s ease-out, height 1s ease-out;
-moz-transition: width 1s ease-out, height 1s ease-out;
-o-transition: width 1s ease-out, height 1s ease-out;
transition: width 1s ease-out, height 1s ease-out;
}
a:hover img {
left:50px;
}
Fiddle

visibility: visible and youtube

I have a menu created with ul/li lists.
To create a nice effect, I have the following css:
#menu ul {
/* ... */
visibility:hidden;
/* ... */
}
#menu li:hover > ul {
/* ... */
visibility: visible;
/* ... */
}
You can view the full code here: http://www.red-team-design.com/css3-animated-dropdown-menu.
The menu works fine without any issues unless I embed a Youtube video (e.g. a random video - <iframe src="http://www.youtube.com/embed/e80qhyovOnA?rel=0" frameborder="0" width="420" height="315"></iframe>).
I have troubleshooted the problem to the visibility css property and when using Chrome.
Is there a way I can change the CSS to keep the bouncing effect?
Replacing this with display:none works but it looses the bouncing effect. There seems to be a conflict with Youtube's code. Ideally I do not touch anything within the iframe unless it is automated as videos are embedded via WYSIWYG.
Thank you.
Youtube CSS makes something wrong with transitions, so, just change
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
to
-webkit-transition: opacity .2s ease-in-out;
-moz-transition: opacity .2s ease-in-out;
-ms-transition: opacity .2s ease-in-out;
-o-transition: opacity .2s ease-in-out;
transition: opacity .2s ease-in-out;
It helps me a lot.