I'm trying to achieve a typing effect with multiple lines in CSS.
This was a good reference point I followed:
CSS animated typing
https://css-tricks.com/snippets/css/typewriter-effect/
Now my desired effect is that the first border-right's visibility be hidden once the first blinking cursor's animation ends. A the border-right is still on screen after the animation ends and I want it not to be visible. (As if enter button on a keyboard was pressed.) How would I go about that?
https://jsfiddle.net/6567onn8/5/
.typewriter h1 {
text-align: center;
overflow: hidden;
font-size: 100%;
border-right: .15em solid #fff;
white-space: nowrap;
/* keeps content in one line */
letter-spacing: .15em;
animation: typing 2.5s steps(22, end), blink-caret .75s step-end;
}
.typewriter h2 {
font-size: 100%;
white-space: nowrap;
overflow: hidden;
border-right: .15em solid black;
-webkit-animation: typing 2s steps(26, end), blink-caret 1s step-end infinite;
-webkit-animation-delay: 3s;
-webkit-animation-fill-mode: both;
-moz-animation: typing 2s steps(26, end), blink-caret 1s step-end infinite;
-moz-animation-delay: 3s;
}
/* The typing effect */
#keyframes typing {
from {
width: 0
}
to {
width: 9em;
}
}
#keyframes blink-caret {
from, to {
border-color: transparent
}
50% {
border-color: #000;
}
}
<div class="typewriter">
<h1>Hi. I'm Andy.</h1>
<h2>I love learning.</h2>
</div>
Just take out infinite
.typewriter h1 {
text-align: center;
overflow: hidden;
font-size: 100%;
border-right: .15em solid #fff;
white-space: nowrap;
/* keeps content in one line */
letter-spacing: .15em;
animation: typing 2.5s steps(22, end), blink-caret .75s step-end;
}
.typewriter h2 {
font-size: 100%;
white-space: nowrap;
overflow: hidden;
border-right: .15em solid black;
-webkit-animation: typing 2s steps(26, end), blink-caret 1s step-end;
-webkit-animation-delay: 3s;
-webkit-animation-fill-mode: both;
-moz-animation: typing 2s steps(26, end), blink-caret 1s step-end;
-moz-animation-delay: 3s;
}
/* The typing effect */
#keyframes typing {
from {
width: 0
}
to {
width: 9em;
}
}
#keyframes blink-caret {
from, to {
border-color: transparent
}
50% {
border-color: #000;
}
}
<div class="typewriter">
<h1>Hi. I'm Andy.</h1>
<h2>I love learning.</h2>
</div>
body{
margin: 0;
font-family: 'Pacifico', cursive;
}
.blackboard-wrapper {
width: 100vw;
height: 100vh;
background-image: repeating-linear-gradient(to bottom,#26180B 70%,#362418 77%,#77736A 78%,#655444 78%);
}
.black-board {
height: 360px;
width: 800px;
transform: translateY(70px);
margin: 0 auto;
background-image: repeating-linear-gradient(to bottom,#000000 77%,#111111 78%,#222222 77%,#000000 78%);
border-width: 15px;
border-style: groove;
border-color: #2E1E11;
position: relative;
color: #ffffff;
}
.date {
position: absolute;
left: 15px;
top: 10px;
}
.date > span {
display: block;
margin-bottom: 5px;
}
.black-board::before {
position: absolute;
left: 0;
content: "";
right: 0;
background-color: #afafaf;
height: 2px;
top: 94px;
}
.topic {
position: absolute;
top: 28px;
left: 50%;
transform: translateX(-50%);
text-decoration: underline;
word-spacing: 8px;
}
.writing {
position: absolute;
top: 120px;
left: 15px;
right: 15px;
bottom: 15px;
}
.writing::after,
.writing::before {
position: absolute;
letter-spacing: 2px;
font-size: 30px;
animation-name: write;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-timing-function: cubic-bezier(.7,.45,.97,.36);
}
.writing::before{
font-size: 25px;
content:"This is cool NAAA???";
top: 70px;
color: #1FBEA6;
animation-name: write2;
animation-duration: 2s;
animation-iteration-count: 1;
animation-timing-function: cubic-bezier(.7,.45,.97,.36);
}
#keyframes write{
0%{content:"";}
3%{content:"V_";}
6%{content:"VI_";}
9%{content:"VIK_";}
12%{content:"VIKA_";}
15%,25%{content:"VIKAS";}
28%{content:"VIKA_";}
31%{content:"VIK_";}
34%{content:"VI_";}
37%{content:"V_";}
40%,50%{content:"";}
53%{content:"P_";}
56%{content:"PA_";}
59%{content:"PAT_";}
62%{content:"PATE_";}
65%,75%{content:"PATEL";}
78%{content:"PATE_";}
81%{content:"PAT_";}
84%{content:"PA_";}
88%{content:"P_";}
91%,100%{content:"";}
}
#keyframes write2{
0%{content:"";}
5%{content:"T_";}
10%{content:"Th_";}
15%{content:"Thi_";}
20%{content:"This_ ";}
25%{content:"This i_";}
30%{content:"This is_";}
35%{content:"This is_ ";}
40%{content:"This is c_";}
45%{content:"This is co_";}
50%{content:"This is coo_";}
55%{content:"This is cool_";}
65%{content:"This is cool N_";}
70%{content:"This is cool NA_";}
75%{content:"This is cool NAA_";}
80%{content:"This is cool NAAA";}
85%{content:"This is cool NAAA?";}
90%{content:"This is cool NAAA??";}
95%{content:"This is cool NAAA???";}
100%{content:"This is cool NAAA???";}
}
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<div class="blackboard-wrapper">
<div class="black-board">
<div class="date">
<span>DATE</span>
<span>25|oct|2018</span>
</div>
<div class="topic">TYPING EFFECT USING CSS</div>
<div class="writing"></div>
</div>
</div>
https://codepen.io/Vikaspatel/pen/mzarrO
.wrapper {
height: 100vh;
/*This part is important for centering*/
display: flex;
align-items: center;
justify-content: center;
}
.typing-demo {
width: 22ch;
animation: typing 2s steps(22), blink .5s step-end infinite alternate;
white-space: nowrap;
overflow: hidden;
border-right: 3px solid;
font-family: monospace;
font-size: 2em;
}
#keyframes typing {
from {
width: 0
}
}
#keyframes blink {
50% {
border-color: transparent
}
}
<div class="wrapper">
<div class="typing-demo">
This is a typing demo.
</div>
</div>
Easiest way of doing it in CSS.
Related
I am trying to implement the typewriting effect on two lines for a webpage (black background), where I am not able to execute a cursor blinking once the second sentence has been typed out.
I have put out the HTML and CSS code. Any help in rectifying where I've gone wrong will be helpful.
HTML:
<div class="typewriter">
<h1>Hi,</h1>
<h2>This is <span style="color: orange">ABC.</span></h2></div>
CSS:
.typewriter h1 {
color: #fff;
font-family: 'DM Mono', monospace;
overflow: hidden;
font-size: 80px;
border-right: .15em solid black;
white-space: nowrap;
letter-spacing: .15em;
width: 4ch;
animation: typing 2.5s steps(4, end), blink-caret .75s step-end 4;
}
.typewriter h2 {
color: #fff;
font-family: 'DM Mono', monospace;
font-size: 40px;
white-space: nowrap;
overflow: hidden;
border-right: .15em solid orange;
width: 20ch;
animation: typing2 2s steps(20, end), blink-caret 1s step-end;
animation-delay: 3s;
animation-fill-mode: both;
}
#keyframes typing {
from {
width: 0
}
to {
width: 3em;
}
}
#keyframes typing2 {
from {
width: 0
}
to {
width: 20em;
}
}
#keyframes blink-caret {
from, to {
border-color: transparent
}
50% {
border-color: white;
}
}
I don't know why this works, but it works. Let me know if it gives the desired effect.
.typewriter h2 {
color: #fff;
font-family: 'DM Mono', monospace;
font-size: 40px;
white-space: nowrap;
overflow: hidden;
border-right: .15em solid orange;
//this is what i changed
width: 12ch;
animation: typing2 2s steps(12, end), blink-caret 1s step-end infinite;
////
animation-delay: 3s;
animation-fill-mode: both;
}
#keyframes typing2 {
from {
width: 0
}
to {
//this is what i changed
width: 12ch;
////
}
}
I am trying to get my text that has a typing effect to center in the middle of this div but I can't get it to work. Here below you can see my code that I tried using but it would fit the job. It will still display the text at the left of the div.
<header class="masthead text-white text-center">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-xl-10 css-typing mx-auto ">
<p>
Hey! Ik ben
</p>
<p>
Tom Faas
</p>
</div>
</div>
</div>
</header>
The CSS code:
.css-typing p {
border-right: .15em solid white;
font-family: "Courier";
font-size: 14px;
white-space: nowrap;
overflow: hidden;
}
.css-typing p:nth-child(1) {
width: 7.3em;
text-align: center;
-webkit-animation: type 2s steps(40, end);
animation: type 2s steps(40, end),
blinkTextCursor 500ms steps(44) infinite normal;;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.css-typing p:nth-child(2) {
width: 7.3em;
font-size: 200%;
text-align: center;
opacity: 0;
-webkit-animation: type2 2s steps(40, end);
animation: type2 2s steps(40, end),
blinkTextCursor 500ms steps(44) infinite normal;;
-webkit-animation-delay: 2s;
animation-delay: 2s;
animation-fill-mode: forwards;
}
#keyframes type {
0% {
width: 0;
}
99.9% {
border-right: .15em solid white;
}
100% {
opacity: 1;
border: none;
}
}
#-webkit-keyframes type {
0% {
width: 0;
}
99.9% {
border-right: .15em solid white;
}
100% {
opacity: 1;
border: none;
}
}
#keyframes type2 {
0% {
width: 0;
}
1% {
opacity: 1;
}
99.9% {
border-right: .15em solid white;
}
100% {
opacity: 1;
border: none;
}
}
#-webkit-keyframes type2 {
0% {
width: 0;
}
1% {
opacity: 1;
}
99.9% {
border-right: .15em solid white;
}
100% {
opacity: 1;
border: none;
}
}
As you can see in the example I tried using the mx-auto tagg but It won't center the text and will still put it at the left of the div.
add below CSS property where you use mx-auto. It will center your text.
display: flex;
flex-direction: column;
align-items: center;
Since my title is all there is to ask,
here is my html code:
<div class="line typewriter">
<h1> My name </h1>
<h4>Data Scientist | Environmental Enthusiast |   Traveller</h4>
</div>
and my css code:
.line {
/* position: relative; */
top:50%;
width: 50%;
margin: 0 auto;
text-align: center;
white-space: nowrap;
overflow: hidden;transform: translateY(~50%);
}
.typewriter {
animation: type 7s steps(35, end) 0.5s,
blinkTextCursor 500ms steps(10) infinite normal;
/* overflow: hidden;
white-space: nowrap; */
}
#keyframes type {
from {
width:0%;
}
to {
width: 100%;
}
}
Also my text-writer does not look smooth, how can I make it smoother?
It will go along as per content.
Try this:
.typewriter{
position:relative;
display: inline-block;
}
.typewriter h4 {
color: #000;
font-family: monospace;
overflow: hidden;
border-right: .15em solid orange;
white-space: nowrap;
margin: 0 auto;
letter-spacing: .15em;
animation: typing 3.5s steps(30, end), blink-caret .5s step-end infinite;
}
/* The typing effect */
#keyframes typing {
from {
width: 0
}
to {
width: 100%
}
}
/* The typewriter cursor effect */
#keyframes blink-caret {
from,
to {
border-color: transparent
}
50% {
border-color: orange
}
}
<div class=" typewriter">
<h4>Data Scientist | Environmental Enthusiast |   Traveller</h4>
</div>
I have some misbehaving text in a CSS animation.
The text appears to "type" itself out, and then end with a blinking cursor. It does this well, but when it's done typing a line that line tends to "float" or "shift" itself over to the center of the page.
I am centering the text with text-align: center; as well as with a flexbox (to get it center of the page).
Here's a link to a JSFiddle
And here's some code:
html, body {
height: 100%;
width: 100%;
}
body {
overflow-x: hidden;
overflow-y: hidden;
}
.do-you-even-flexbox, .content {
position:relative;
top:0;
width:100%;
height:100%;
}
.content {
padding:8px 20px 15px;
display:flex;
align-content:center;
}
.box {
height:20%;
margin:auto
}
h1 {
text-align: center;
font-size: 75px;
margin-top: 0em;
margin-bottom: 0em;
padding: 0em;
}
h2 {
font-size: 50px;
text-align: center;
margin-top: 0em;
margin-bottom: 0em;
padding: 0em;
}
h3 {
font-size: 25px;
text-align: center;
margin-top: 0em;
margin-bottom: 0em;
padding: 0em;
}
a {
color: #000;
text-decoration: none;
}
.content h1 {
white-space:nowrap;
overflow:hidden;
-webkit-animation: typing 5s steps(60, end);
-moz-animation: typing 5s steps(60, end);
}
.content h2 {
white-space:nowrap;
overflow:hidden;
-webkit-animation: typing 5s steps(60, end);
-webkit-animation-delay: 4s;
-webkit-animation-fill-mode:both;
-moz-animation: typing 5s steps(60, end);
-moz-animation-delay:4s;
-moz-animation-fill-mode:both;
}
.content h3 {
white-space: nowrap;
overflow: hidden;
-webkit-animation: typing 10s steps(120, end);
-webkit-animation-delay: 8s;
-webkit-animation-fill-mode: both;
-moz-animation: typing 10s steps(120, end);
-moz-animation-delay: 8s;
-moz-animation-fill-mode: both;
}
span {
-webkit-animation: blink 1s infinite;
-moz-animation: blink 1s infinite;
}
#-webkit-keyframes typing {
from { width: 0; }
to { width: 100%; }
}
#-webkit-keyframes blink {
to { opacity: .0;}
}
#-moz-keyframes typing {
from { width: 0; }
to { width: 100%; }
}
#-moz-keyframes blink {
to { opacity: .0; }
}
And here's some HTML that goes with it:
<i class="do-you-even-flexbox"></i>
<div class="content">
<div class="box">
<h1>This wasn't the same as the fiddle code.</p>
<h2>So I've removed some details so it's similar to the fiddle.</p>
<h3>~ get in touch ~ about me ~ blog ~ projects ~ my portfolio ~<span> |</span></h3>
</div>
</div>
well, the problem seems to be with the animation from 0 to 100%, since Heading tags are blocks, and blocks always are 100% percent from its container, the animation actually goes from 0 to the total width of the page. What you are trying to do here its a little bit tricky but can be done nesting a tag inside every Heading tag and animating that tag while giving each heading tag inline behavior which ensures the width is not 100% of the container but just the text.
html, body {
height: 100%;
width: 100%;
}
body {
overflow-x: hidden;
overflow-y: hidden;
}
.do-you-even-flexbox, .content {
position:relative;
top:0;
width:100%;
height:100%;
}
.content {
padding:8px 20px 15px;
display:flex;
align-content:center;
}
.box {
height:20%;
margin:auto
text-align: center;
}
h1, h2, h3 {
display: inline-block;
position: relative;
background-color: #cccccc;
}
h1 span {
font-size: 75px;
margin: 0;
padding: 0em;
display: block;
background-color: #ff0000;
}
h2 span {
font-size: 50px;
text-align: center;
margin-top: 0em;
margin-bottom: 0em;
padding: 0em;
}
h3 span {
font-size: 25px;
text-align: center;
margin-top: 0em;
margin-bottom: 0em;
padding: 0em;
}
a {
color: #000;
text-decoration: none;
}
.content h1 span {
white-space:nowrap;
overflow:hidden;
-webkit-animation: typing 2s steps(60, end);
-moz-animation: typing 2s steps(60, end);
}
.content h2 {
white-space:nowrap;
overflow:hidden;
-webkit-animation: typing 2s steps(60, end);
-webkit-animation-delay: 2s;
-webkit-animation-fill-mode:both;
-moz-animation: typing 2s steps(60, end);
-moz-animation-delay:2s;
-moz-animation-fill-mode:both;
}
.content h3 {
white-space: nowrap;
overflow: hidden;
-webkit-animation: typing 10s steps(120, end);
-webkit-animation-delay: 2s;
-webkit-animation-fill-mode: both;
-moz-animation: typing 2s steps(120, end);
-moz-animation-delay: 2s;
-moz-animation-fill-mode: both;
}
span.caret {
-webkit-animation: blink 1s infinite;
-moz-animation: blink 1s infinite;
}
#-webkit-keyframes typing {
from { width: 0; }
to { width: 100%; }
}
#-webkit-keyframes blink {
to { opacity: .0;}
}
#-moz-keyframes typing {
from { width: 0; }
to { width: 100%; }
}
#-moz-keyframes blink {
to { opacity: .0; }
}
<i class="do-you-even-flexbox"></i>
<div class="content">
<div class="box">
<h1><span>This</span></h1>
<br>
<h2><span>This is a subtitile</span></h2>
<br>
<h3><span>These are links to things on other pages.<span class="caret">|</span> </span></h3>
</div>
</div>
I have this HTML:
<div id="container">
<div id="content">
<h2 class="frame1">Loriam Ipisum</h2>
<h2 class="frame2">Loriam Ipisumsad</h2>
</div>
</div>
And this CSS:
body{margin: 0; padding: 0;}
#container{
width: 100%;
top: 200px;
border: 1px solid black;
text-align: center;
position: relative;
overflow: hidden;
}
#content{
width: 300px;
height: 50px;
border: 1px solid blue;
position: relative;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
#content h2{
position: relative;
display: inline-block;
}
#content h2.frame1{
-webkit-animation-delay: 0s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
}
#content h2.frame2{
-webkit-animation-delay: 3s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
}
#-webkit-keyframes efeito1{
0%{
left: 0;
opacity: 0;
}
50%{
opacity: 0.4;
left: 100px;
opacity: 0.4;
left: 200;
}
100%{
opacity: 0;
left: 300px;
opacity: 0.4;
}
}
What I want to do is: I want both .frames be at the same LINE. SO when I apply the animation, it will happen at the same place, giving a nice effect. I want them to be at the same line, at the same place but without one text be upon the other looking like a mess...
I tried to use the overflow: Hidden: but didn't work, the texts stays one above the other...
I want to apply, this effect: http://codepen.io/anon/pen/LcwKj/
Any suggestion? Thanks !
Is this effect what you are aiming for:
HTML
<div id="container">
<div id="content">
<h2 class="frame1">Loriam Ipisum</h2>
<h2 class="frame2">sad</h2>
</div>
</div>
CSS
body{margin: 0; padding: 0;}
#container{
width: 100%;
top: 200px;
border: 1px solid black;
text-align: center;
position: relative;
overflow: hidden;
}
#content{
width: 100%;
height: 50px;
border: 1px solid blue;
position: relative;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
#content h2{
position: absolute;
display: inline-block;
}
#content h2.frame1{
-webkit-animation-delay: 0s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
opacity:0;
}
#content h2.frame2{
-webkit-animation-delay: 3s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
opacity:0;
position:absolute;
}
#-webkit-keyframes efeito1{
0%{
opacity: 0;
}
100%{
opacity: 100;
}
}