How to stop two elements effecting each other? - html

I'm creating an animation https://codepen.io/adsler/pen/bGNWxOe and I've created a div class. I've adjusted this with css. It works. However, as soon as I introduce another div class, it's not only effected by the first, but there seems to be no way of selecting it with css.
So here is the original:
Html:
<div
class="random">four<br>
three<br>zero<br>nine</div>
Css:
.random {background.
color:red;background-image:
linear-gradient(black,
white); width: 10px; height:
200px; font-weight: 900;
position:relative; font-
size:20px; left: 20x;
top:60px; filter:sepia(0);
color:black; border-radius:
100px; box-shadow: 90px 90px
30px 90px #000; text-align:
center;}
.random {animation: turn 30s
ease-in infinite; animation.
direction: alternate.
reverse;animation-delay:
2s;}
#keyframes turn {
0%
{transform:rotate(1400deg);
width: 1px} 30%.
{transform:rotatex(7000deg);
font-size: 30px;} 40%
{transform:rotatez(360deg);
width: 13em} 70%
{width: 10em;}100%
{opacity: 0.9;}
That's fine but then, when I introduce the next sequence, by way of a div class, I can't find the selector with css and the style is influenced by the first div.
<div
class="starring">Starring
</div>
.starring {margin-top: 500px
!important; font-size: 50px
!important;}
So I tried specificity.
.random.starring {margin.
top: 500px
!important; font-size: 50px
!important;}
Still unable to select starring with css and style still influenced by previous div.

In your codepen under the html section you have one too many ending 's in the first part.
Like this:
<div class="random">four<br>three<br>zero<br>nine</div></div>
<div class="starring">Starring</div>
Which should be:
<div class="random">four<br>three<br>zero<br>nine</div>
<div class="starring">Starring</div>
Next thing is - you don't end your animation in your css part
#keyframes turn {
0%{transform:rotate(1400deg);
width: 1px}
30%{transform:rotatex(7000deg);
font-size: 30px;}
40% {transform:rotatez(360deg);
width: 13em}
70% {width: 10em;}100%
{opacity: 0.9;}
Here you need a last } to actually wrap up the turn tag.
Like this:
#keyframes turn {
0%{transform:rotate(1400deg);
width: 1px}
30%{transform:rotatex(7000deg);
font-size: 30px;}
40% {transform:rotatez(360deg);
width: 13em}
70% {width: 10em;}100%
{opacity: 0.9;}
}
Make these changes and it works as supposed.
.starring {
color:red;
}
Works for me.

The problem is you are missing a closing } for your turn keyframe.
#keyframes turn {
0% {
transform:rotate(1400deg);
width: 1px
}
30% {
transform: rotatex(7000deg);
font-size: 30px;
}
40% {
transform: rotatez(360deg);
width: 13em
}
70% {
width: 10em;
}
100% {
opacity: 0.9;
}
}
And then for your second div, this will work:
.starring {
margin-top: 500px !important;
font-size: 50px !important;
}

I feel best solution here would be giving css to 1 element.
Add position:absolute to 1 of the element. And further accordingly adjust the element wherever you want using margin-bottom and margin-left!

Related

How to make CSS multiline typewriter effect responsive?

Goal & Issue: I wanted to have a responsive typewriter effect in my header where text would resize and lines would break with the screen. To sorta' achieve that I made each line its own p with it's own animation & keyframes, but this isn't responsive. I tired to make the header a flexbox, but it doesn't seem to flex at al--the text goes off screen when I simulate a mobile view. I don't want to use JavaScript, so I'm looking to stick with CSS.
Main Questions
Is it possible to have multi-line typewriter text wrap responsively?
Most of the other answers to this question suggested using a flexbox. I've implemented them successfully elsewhere, but I'm having difficulties with this component. What am I doing wrong? Should I use media queries instead and/or alongside a flexbox?
Small Side Questions
Do I even need to width: 100% in my keyframes? With it enabled the cursor runs past the end of the first two lines of text (but not the others).
Do I need to define html and body as height: 100% for this component?
Here's the codepen: https://codepen.io/nat-jt/pen/rNedexG and the code:
HTML:
<header class="header-main">
{% include nav.html %}
<!-- Typewriter -->
<div class="screen">
<h1 class="anim-typewriter1">_Hi, I'm Natalie</h1>
<p class="anim-typewriter2">
_I do user research + ethnography
</p>
<p class="anim-typewriter3">
_I use my background in anthropology + cognitive science to try
</p>
<p class="anim-typewriter4">
& understand the intersections of lived experiences + contexts
</p>
<p class="anim-typewriter5">
_In my work I break complex problems into understandable
</p>
<p class="anim-typewriter6">
components & provide actionable findings
</p>
</div>
</header>
SASS:
html.header-main, body.header-main
height: 100%
header.header-main
position: relative
z-index: 1
display: flex
flex-direction: column
align-items: flex-start
justify-content: flex-start
width: 100%
height: 100vh // calc(100vh - 8em)
min-height: 100%
padding: 4em
overflow: hidden
background-color: rgb(25,25,25)
h1, p
position: relative
top: 25%
// width: 35em
// width: 65ch
border-right: 2px solid $comp-green
color: rgba(255,255,255,.75)
font-family: 'Anonymous Pro', monospace
font-size: 130%
text-align: left
white-space: nowrap
overflow: hidden
//transform: translateY(-50%)
h1
font-size: 250%
font-weight: 600
width: 9.05em
width: 16ch
/* Animation */
.anim-typewriter1
width: 9.05em
width: 16ch
animation: typing1 1.5s steps(16) 350ms 1 normal both
.anim-typewriter2
width: 18.75em
width: 33ch
margin-top: .5em
opacity: 0
animation: typing2 2s steps(33) 3s 1 normal both
.anim-typewriter3
width: 35.7em
width: 63ch
margin-top: 1em
opacity: 0
animation: typing3 2s steps(63) 5s 1 normal both
.anim-typewriter4
width: 35.1em
width: 62ch
margin-bottom: 1em
opacity: 0
animation: typing4 2s steps(62) 7s 1 normal both,cursor_blink .8s steps(44) infinite normal
.anim-typewriter5
width: 31.7em
width: 56ch
margin-top: 1em
opacity: 0
animation: typing5 2s steps(56) 9.5s 1 normal both,cursor_blink .8s steps(44) infinite normal
.anim-typewriter6
width: 22.7em
width: 40ch
opacity: 0
animation: typing6 2s steps(40) 11.5s 1 normal both,cursor_blink .8s steps(44) infinite normal
#keyframes typing1
from
width: 0
to
width: 100%
99.9%
border-right: 2px solid $comp-green
100%
border-right: none
#keyframes typing2
from
width: 0
to
width: 100%
1%
opacity: 1
99.99%
border-right: 2px solid $comp-green
100%
opacity: 1
border-right: none
#keyframes typing3
from
width: 0
// to
// width: 35.7em
1%
opacity: 1
99.99%
border-right: 2px solid $comp-green
100%
opacity: 1
border-right: none
#keyframes typing4
from
width: 0
// to
// width: 35.1em
1%
opacity: 1
99.99%
border-right: 2px solid $comp-green
100%
opacity: 1
border-right: none
#keyframes typing5
from
width: 0
to
width: 31.7em
1%
opacity: 1
99.99%
border-right: 2px solid $comp-green
100%
opacity: 1
border-right: none
#keyframes typing6
from
width: 0
to
width: 22.7em
1%
opacity: 1
100%
opacity: 1
#keyframes cursor_blink
from
border-right-color: $comp-green
to
border-right-color: transparent
I have seen the other questions related to this issue, and while it helped me clean some things up I still can't work out a solution from their answers.
Thank you for your time & help! Please let me know if there is any other information I can provide.

What are the #keyframes identifier rules in CSS3?

I am working on an animation and I was wondering what were the rules for the #keyframe identifier.
For instance, I was doing the following but it didn't work.
Code:
#banner {
width: 468px;
height: 60px;
background-color: red;
color: white;
text-align: center;
padding-top: 30px;
font-weight: bold;
font-size: 2em;
animation-name: #banner;
animation-duration: 4s;
}
#keyframes #banner {
from: {background-color: red;}
to: {background-color: green;}
}
<div id="banner">Just a banner</div>
The #keyframes rule specifies the animation code.
The animation is created by gradually changing from one set of CSS styles to another.
During the animation, you can change the set of CSS styles many times.
Specify when the style change will happen in percent, or with the keywords "from" and "to", which is the same as 0% and 100%. 0% is the beginning of the animation, 100% is when the animation is complete.
Tip: For best browser support, you should always define both the 0% and the 100% selectors.
Note: The !important rule is ignored in a keyframe
Read more at https://developer.mozilla.org/en-US/docs/Web/CSS/#keyframes

How can I cause moving text to gradually disappear and reappear rather than teleporting at the end of an animation? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have some right to left scrolling text that teleports back to the origin at the end of the animation, while I am more so looking for it to disappear out of and appear into the margin.
.example1 {
height: 50px;
overflow: hidden;
position: relative;
}
.example1 h3 {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
color: white;
line-height: 50px;
animation: example1 10s linear infinite;te
}
#keyframes example1 {
from {
margin-left: 60%;
width: 300%;
}
to {
margin-left: 35%;
width: 100%;
}
}
body {
background-color: black;
}
<div class="example1">
<h3>text</h3>
</div>
If you need your CSS animation to only run once, you have to set the animation-iteration-count property to 1 (in fact, to not set it at all, as 1 is its default value).
You're currently setting it to infinite, using the animation shorthand, which sets multiple animation properties in one single declaration. Just remove infinte from that line. You should also remove the te following that declaration, which is invalid CSS.
To have your animation animate multiple properties, you can add as many animatable properties to your keyframes and they will animate accordingly. In your case, adding a 50% keyframe with opacity:1 and adding opacity:0 to the to keyframe will make your element fade from 1 to 0 starting at half of the animation until its end.
Using animation-timing-function, particularly with timing functions (a.k.a. as easings), allows adding acceleration and deceleration to animations, making them look more "natural", especially when used on movement animations.
Another handy property of CSS animations is the animation-fill-mode. It allows setting the animated properties to the values they have been animated to, when the animation ends (as opposed to being reset to any applying CSS). This avoids the "jump" whenever you have animated a property to a different value that what normally applies to it.
Last note, on performance: to make sure your animations run smoothly on any device, you should only animate properties which do not trigger repaints on subsequent elements. In fact, you should strive to ever animate only 2 properties: transform and opacity. In your case, rather than animating margin-left, which moves your element around and triggers repaint on subsequent elements in DOM, you should never actually move it and use transform to paint it at different positions.
Here's an example (not sure if this is what you asked for, but you can play around with it some more):
body {
overflow-x: hidden;
background-color: #212121;
}
.example1 h3 {
color: white;
font-size: 3rem;
margin: 0;
line-height: 50px;
animation: example1 5s cubic-bezier(.4,0,.2,1) forwards;
}
#keyframes example1 {
from{
transform: translateX(107%);
}
38% {
opacity: 1;
}
42% {
transform: translateX(35%);
}
60% {
opacity: 0;
transform: translateX(35%);
}
62% {
transform: translateX(0);
opacity: 0;
}
to {
opacity: 1;
}
}
<div class="example1">
<h3>text</h3>
</div>
If, on the contrary, you want your animation looping but want to simply create a smooth transition between end and start, the golden rule is in both from and to keyframes the animated properties have to have the same values (because default value of transform:translateX() is 0 and of opacity is 1, I don't need to set them in from - that's the starting point):
body {
overflow-x: hidden;
background-color: #212121;
}
.example1 h3 {
color: white;
text-align:right;
padding-right: 1rem;
font-size: 3rem;
margin: 0;
line-height: 50px;
animation: example1 5s cubic-bezier(.4,0,.2,1) infinite;
}
#keyframes example1 {
38% {
opacity: 1;
}
42% {
transform: translateX(-60%);
}
58% {
opacity: 0;
transform: translateX(-60%);
}
62% {
transform: translateX(0);
opacity: 0;
}
to {
opacity: 1;
}
}
<div class="example1">
<h3>text</h3>
</div>
For more on animation syntax and examples, I recommend MDN, a well curated documentation library, joint effort of Mozilla, Google, Microsoft and many, many others. Arguably, its most useful feature is linking, in the Specifications section, at the bottom, currently applying standards for the respective property or method, so you don't have to waste time tracking them yourself.
You can use more keyframes percentage to control better your animation in stead of using just two keyframes (from/to).
Below a quick example:
.example1 {
height: 50px;
overflow: hidden;
position: relative;
}
.example1 h3 {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
color: white;
line-height: 50px;
animation: example1 10s linear infinite;te
}
#keyframes example1 {
0% {
margin-left: 60%;
width: 300%;
opacity: 0;
}
50% {
opacity: 1;
}
100% {
margin-left: 35%;
width: 100%;
opacity: 0;
}
}
body {
background-color: black;
}
<div class="example1">
<h3>text</h3>
</div>
Instead of animating the margin-left style you should animate the left style, example:
.example1 {
height: 50px;
width: 400px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.example1 h3 {
position: absolute;
top: 0;
left: 100%;
line-height: 50px;
animation: example1 10s linear infinite;
}
#keyframes example1 {
from {
left: 100%;
}
to {
left: -10%;
}
}
<div class="example1">
<h3>text</h3>
</div>

html css superimpose several images

How to superimpose several images in one line using css and html?
Ex: If my cursor is on image1, I want all images to the right be push to the right like that I can see image1
Here what I have done so far:
HTML
<body>
<div class="deck">
<img src="https://image.tmdb.org/t/p/w220_and_h330_bestv2/kXlrGioGfFKOvibpsPzzGx16cP2.jpg" alt="testimage">
<img src="https://image.tmdb.org/t/p/w220_and_h330_bestv2/zzfwhweu5reCv2Loqzon7Q5WAd5.jpg" alt="testimage">
<img src="https://image.tmdb.org/t/p/w220_and_h330_bestv2/sGuZHYvu0mXeQCwvJ5yzk2Yoytq.jpg" alt="testimage">
<img src="https://image.tmdb.org/t/p/w220_and_h330_bestv2/4Ar01t6sW1ZZBcbz2R1wqjzIBdr.jpg" alt="testimage">
</div>
</body>
CSS
.deck {overflow:hidden}
.deck img {position:relative; float:left; width:185px; height:278px}
.deck img + img {margin-left: -160px;}
.deck img:hover {z-index:9999; border:1px solid red; background: pink}
https://jsfiddle.net/53ryuapx/
You can use the ~ selector to select all images following the one you hover. And as the images are positioned relatively, you can combine this with a left value:
.deck img:hover ~ img {
left: 160px;
}
Might I even suggest you combine this with the relatively new clip-path property? Unfortunately browser support is not great.
.deck img:hover ~ img {
left: 160px;
clip-path: inset(0 160px 0 0)
}
Edit: There are several ways to animate this depending on the result you prefer. This might need some tewaking to get to the result you want, but this should get you started. What's happening here is we declare a keyframe animation called slidein. When an image is hovered, the images to the right are animated using animation: slidein .2s. See the effect in this JSFiddle:
#keyframes slidein {
0% {
left: 0;
clip-path: inset(0 0 0 0);
}
100% {
left: 160px;
clip-path: inset(0 160px 0 0);
}
}
.deck img:hover ~ img {
left: 160px;
clip-path: inset(0 160px 0 0);
animation: slidein .2s;
}

Last image slides too fast

It is a slide in a html using css.
However when it slides to the last image (the duration of the last image is too short), it carries on to the first too fast. All the rest of the images are fine.
Here is the html part:
<div id="slider" style="text-align: center">
<figure>
<img src="pics/img01.png">
<img src="pics/img02.png">
<img src="pics/img03.png">
<img src="pics/img04.png">
<img src="pics/img05.png">
</figure></div>
Here is the css part:
#keyframes slidy{
0%{left: 0%;}
20%{left: 0%;}
35%{left: -100%;}
45%{left: -150%;}
55%{left: -200%;}
65%{left: -250%;}
75%{left: -300%;}
95%{left: -350%;}
100%{left: -400%;}
}
body { margin: 100px left; }
div#slider { overflow: hidden; }
div#slider figure img { width: 20%; float: left; }
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
Yeah, I fixed your slideshow issue. It runs very smoothly now Check the codepen here.
The main thing about CSS sliders you have to keep in mind is the width you have given & the way you slide your different slides within that given width. Its all about maintaining that balance between width & the time taken to complete that one cycle of covering the width.
In your case you had 5 images but have broken your #keyframes into too many levels(the levels depend on the width of each of your images).
I have included an image showing how it works & broken your #keyframes as shown below:
#keyframes slidy{
0%{left: 0%;}
25%{left: -100%;}
50%{left: -200%;}
75%{left: -300%;}
100%{left: -400%;}
}
Check this codepen & let me know if it fixes your issue