How to display css animated text inline with normal text? [duplicate] - css

This question already has answers here:
CSS transform doesn't work on inline elements
(2 answers)
Closed 4 months ago.
I'm trying to display a sentence where only a few words in the sentence are animated by CSS. While I can get the words inline using <span>, the animation stops working. If I wrap it in something else like <p> the animation works but doesn't display inline.
.scary p {
animation: .8s shake infinite alternate;
}
.scary span {
display: inline-block;
animation: .8s shake infinite alternate;
}
#keyframes shake {
0% { transform: skewX(-15deg); }
5% { transform: skewX(15deg); }
10% { transform: skewX(-15deg); }
15% { transform: skewX(15deg); }
20% { transform: skewX(0deg); }
100% { transform: skewX(0deg); }
}
<div class="scary">
Something has gone <p>terribly wrong</p>, what should we do?
</div>
<br>
<div class="scary">
Something has gone <span>terribly wrong</span>, what should we do?
</div>
How can I display inline text that is animated?

Change the display of the span to inline-block. It has to be inline-block specifically and not inline or block since the animation uses skew, which only works on things that aren't inline, and you also need the block itself to be inline, hence inline-block.
.scary p {
animation: .8s shake infinite alternate;
}
.scary span {
display: inline-block;
animation: .8s shake infinite alternate;
}
#keyframes shake {
0% { transform: skewX(-15deg); }
5% { transform: skewX(15deg); }
10% { transform: skewX(-15deg); }
15% { transform: skewX(15deg); }
20% { transform: skewX(0deg); }
100% { transform: skewX(0deg); }
}
<div class="scary">
Something has gone <p>terribly wrong</p>, what should we do?
</div>
<br>
<div class="scary">
Something has gone <span>terribly wrong</span>, what should we do?
</div>

Related

CSS animations - initialise animation at last frame

I'm doing some CSS animations inside a modal dialog. Here's the pertinent SCSS:
#keyframes grow {
from {
transform: scale(1);
}
to {
transform: scale(1.1);
}
}
#keyframes shrink {
from {
transform: scale(1.1);
}
to {
transform: scale(1);
}
}
$duration: 0.5s;
$animationFillMode: both;
&:not(.active):hover, &.active {
img {
animation: grow $duration $animationFillMode;
}
}
&:not(.active) {
img {
animation: shrink $duration $animationFillMode;
}
}
This works well but the problem is, when I open the modal, the animations kick in immediately. For example, because when the modal is first open I'm not hovering on one of the elements, the element instantly shrinks from big to small. I want the element to start in the small state when the modal is open.
Is is possible? TIA
Yes it is, use reverse tag.
Example: animation-direction: reverse;

Animation of CSS Pseudo Element not working

I'm trying to spin the a pseudo element, however, while the animation works perfectly on other elements, the pseudo element doesn't move.
HTML:
<div class="spinning">
some content
</div>
CSS:
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
.spinning::before {
content: 'x';
animation: spin 2s infinite linear;
}
jsfiddle: https://jsfiddle.net/7x0tasnh/
Applying the animation rule to the div works, with ::before it doesn't work. What am I missing?
Add display: inline-block to your :before
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
.spinning::before {
content: 'x';
animation: spin 2s infinite linear;
display: inline-block;
}
<div class="spinning"></div>

Hiding scroll bar during animations the CSS way

I have some animations which I use for the purpose of transition. Although the transition is cool, it brings up the horizontal and vertical scrollbars which is pretty ugly.
.bounce-enter-active {
animation: bounce-in .5s;
}
.bounce-leave-active {
animation: bounce-in .5s reverse;
}
#keyframes bounce-in {
0% {
transform: scale(0);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
Is there any where to define to the browser using CSS that no scrollbar must be displayed during these animations, or in other words, Overflow = Hidden WHEN Animating.

Moving a banner in and out of viewport by its width (CSS Only)

Ok, so I'm trying to make an infinite side-scrolling banner, and all is fine if I happen to know the width of what I'm moving. The problem is I don't. The idea is that we should accept a long text, an array of images or similar and make them appear from the right, move all the content to the left until everything has scrolled out of sight and then make it start again.
It should work now if we can get the .sliding-banner element to grow until it contains it's elements, but for some reason I can't achieve it. I'm missing something and don't know what! Argh!
What do you think?
Here's some CSS:
.sliding-banner {
white-space: nowrap;
animation: bannermove 30s linear infinite;
}
.sliding-banner > * {
display: inline-block;
float: none !important;
}
#keyframes bannermove {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}
Thanks!
Edit: removed quotes around bannermove as per Red Mercury's suggestion.
Don't put the animation name into quotes.
#keyframes "bannermove" -> #keyframes bannermove
.sliding-banner {
white-space: nowrap;
animation: bannermove 10s linear infinite;
}
#keyframes bannermove {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}
<div class="sliding-banner">
<img src="http://placekitten.com/200/300"/>
<img src="http://placekitten.com/200/300"/>
<img src="http://placekitten.com/200/300"/>
<div/>

CSS3 Animation to hoverstate and back

I need an element that initially has no animation, then animates to a different state on hover (one time, no loop) and after the hover is gone it should animate back to its original state.
Basically just like you would do it with a :hover style and a transition.
Is there a way to achieve that with a CSS3 animation?
This is my current usecase: http://jsfiddle.net/yjD73/11/
On hover an element fades from opacity: 0 to opacity: 1 and back.
This is what i think is not possible with transitions.
EDIT: As requested here the exact code from jsfiddle
a div with four images
<div class="zoombox">
<img src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=4&center=51.561998,-1.605100">
<img src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=7&center=51.561998,-1.605100">
<img src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=12&center=51.561998,-1.605100">
<img src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=16&center=51.562606,-1.605100">
</div>
images stacked onto each other and simple css animations on hover
.zoombox {
position: relative;
margin: 50px;
float: left;
}
/* initial state */
.zoombox img:not(:first-child) {
position: absolute;
top: 0;
opacity: 0;
}
/* On hover in */
.zoombox:hover img:nth-child(1) {
-webkit-animation: first-in 400ms 0ms 1 normal ease-in both;
}
.zoombox:hover img:nth-child(2) {
-webkit-animation: middle-in 1600ms 0ms 1 linear both;
}
.zoombox:hover img:nth-child(3) {
-webkit-animation: middle-in 1600ms 1200ms 1 linear both;
}
.zoombox:hover img:nth-child(4) {
-webkit-animation: last-in 400ms 2400ms 1 linear both;
}
#-webkit-keyframes first-in {
0% {
-webkit-transform: scale(1);
opacity: 1;
}
100% {
-webkit-transform: scale(1.5);
opacity: 0;
}
}
#-webkit-keyframes middle-in {
0% {
-webkit-transform: scale(0.5);
opacity: 0;
}
25%, 75% {
-webkit-transform: scale(1);
opacity: 1;
}
100% {
-webkit-transform: scale(1.5);
opacity: 0;
}
}
#-webkit-keyframes last-in {
0% {
-webkit-transform: scale(0.5);
opacity: 0;
}
100% {
-webkit-transform: scale(1);
opacity: 1;
}
}
Conic, I have created a JSFiddle that replicates most of what you want with css3 animations.
Here it is.
The code that makes this all possible in CSS is:
#-webkit-keyframes changeImage {
0% {background: url("http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=4&center=51.561998,-1.605100");}
33% {background: url("http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=7&center=51.561998,-1.605100");}
67% {background: url("http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=12&center=51.561998,-1.605100");}
100% {background: url("http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x300&maptype=hybrid&zoom=16&center=51.562606,-1.605100");}
}
Right now the jsfiddle is having the image run through the animation on hover and return to the original image. Let me know if you need any over things to happen and by the way, this won't work on any touch devices as a result of a lack of hover state possibilities.

Resources