Anyone know what I'm doing wrong? I can't put the two elements in the same line and they are in two separate levels.
I would like to recreate, using only HTML and Css, an automatic typewriter effect with variable text.
I am a beginner with HTML and Css so I don't understand much but it would be very nice if someone explained my mistake in detail.
body {
background-color: black;
color: white;
font-size: 100px;
}
h1 {
font-size: 30px;
}
.text_1 {
animation: text1;
}
.text_2 {
animation: text2;
}
.text_1, .text_2 {
overflow: hidden;
white-space: nowrap;
display: inline-block;
position: relative;
animation-duration: 20s;
animation-timing-function: steps(25, end);
animation-iteration-count: infinite;
}
.text_1::after, .text_2::after {
content: "|";
position: absolute;
right: 0;
animation: caret infinite;
animation-duration: 1s;
animation-timing-function: steps(1, end);
}
#keyframes text2 {
0%, 50%, 100% {
width: 0;
}
60%, 90% {
width: 6.50em;
}
}
#keyframes text1 {
0%, 50%, 100% {
width: 0;
}
10%, 40% {
width: 8em;
}
}
#keyframes caret {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
<h1>Hi, i'm a <span class="text_1">Graphic Designer</span><span class="text_2">Photographer</span></h1>
I solved by adding display:flex; align-items: baseline; to h1.
The flexbox items are aligned at the baseline of the cross axis.
By default, the cross axis is vertical. This means the flexbox items
will align themselves in order to have the baseline of their text
align along a horizontal line.
body {
background-color: black;
color: white;
font-size: 100px;
}
h1 {
font-size: 30px;
display:flex;
align-items: baseline;
}
.text_1 {
animation: text1;
}
.text_2 {
animation: text2;
}
.text_1, .text_2 {
overflow: hidden;
white-space: nowrap;
display: inline-block;
position: relative;
animation-duration: 20s;
animation-timing-function: steps(25, end);
animation-iteration-count: infinite;
}
.text_1::after, .text_2::after {
content: "|";
position: absolute;
right: 0;
animation: caret infinite;
animation-duration: 1s;
animation-timing-function: steps(1, end);
}
#keyframes text2 {
0%, 50%, 100% {
width: 0;
}
60%, 90% {
width: 6.50em;
}
}
#keyframes text1 {
0%, 50%, 100% {
width: 0;
}
10%, 40% {
width: 8em;
}
}
#keyframes caret {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
<h1>Hi, i'm a <span class="text_1">Graphic Designer</span><span class="text_2">Photographer</span></h1>
Related
I have been developing a website for my new company and want to include a typewriter effect on the main page, I have found a tutorial by Medium.com and I am running into an issue with adding another span to the code provided, look at the link above to see how it was setup Currently, I have as follows.
h1 {
font-size: 30px;
}
.text_1 {
animation: text1;
}
.text_2 {
animation: text2;
}
.text_1,
.text_2 {
overflow: hidden;
white-space: nowrap;
display: inline-block;
position: relative;
animation-duration: 15s;
animation-timing-function: steps(25, end);
animation-iteration-count: infinite;
}
.text_1::after,
.text_2::after {
content: "|";
position: absolute;
right: 0;
animation: caret infinite;
animation-duration: 1s;
animation-timing-function: steps(1, end);
}
#keyframes text2 {
0%,
50%,
100% {
width: 0;
}
60%,
90% {
width: 6em;
}
}
#keyframes text1 {
0%,
50%,
100% {
width: 0;
}
10%,
40% {
width: 10em;
}
}
#keyframes caret {
0%,
100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
<div style="text-align: center;">
<h2><span class="text_1">Coastal Media Provides</span><span class="text_2">Photography</span></h2>
</div>
How would I go about adding a text_3 to the span, if I do so how they added span2 it does not work? any ideas?
I can see one difference between the snippet provided here and the code written in the blog.
The provided snippet is wrapper inside h2 like this
<div style="text-align: center;">
<h2><span class="text_1">Coastal Media Provides</span><span class="text_2">Photography</span></h2>
</div>
but the css has styling related to h1 and not h2.
h1 {
font-size: 30px;
}
.text_1 {
animation: text1;
}
.text_2 {
animation: text2;
}
I'm trying to animate a scrolling text (in a paragraph) so that it will move from the bottom to the top of a div, scroll out of the div (become invisible) and then loop. Here is the relevant css:
#keyframes showAndScroll {
0% {opacity: 0;}
10% {opacity: 0.85;}
50% {opacity: 0.85;}
60% {opacity: 0;}
100% {opacity: 0;}
}
.infobar {
position: absolute;
width: 100%;
height: 30%;
bottom: 0%;
color: white;
background-color: red;
opacity: 0.75;
text-indent: 30px;
font-size: 200%;
pointer-events: none;
animation-name: showAndScroll;
animation-duration: 40s;
animation-iteration-count: infinite;
}
#keyframes scroll {
0% {
transform: translateY(600%); color: red;
}
50% {
transform: translateY(-200%); color: blue;
}
}
.infobar p {
position: absolute;
width: 100%;
overflow: hidden;
display: inline-block;
animation-name: scroll;
animation-duration: 40s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
And the html code:
<div class="infobar">
<p>
Infobar test
<p>
</div>
I'm having two issues:
The text overlaps the rest of the document. How can I make the paragraph invisible as it hits the edge of its parent div? This effect is what I'm looking for: http://media02.hongkiat.com/marquee-css3-animation//demo/index2.html
For some reason, placing the paragraph at 100% of the div doesn't seem to put it on the "bottom" of the div (I've currently placed it at 600%). Why is this?
Any input is appreciated. Here is my JSfiddle: https://jsfiddle.net/essi/oqh6ok00/1/
Add overflow: hidden; to class .infobar. In this way the overflow is clipped, and your animated element will be visible within edges similarly to what you have shown us in your link example.
#keyframes showAndScroll {
0% {
opacity: 0;
}
10% {
opacity: 0.85;
}
50% {
opacity: 0.85;
}
60% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.infobar {
position: absolute;
width: 100%;
height: 30%;
bottom: 0%;
color: white;
background-color: red;
opacity: 0.75;
text-indent: 30px;
font-size: 200%;
pointer-events: none;
animation-name: showAndScroll;
animation-duration: 40s;
animation-iteration-count: infinite;
overflow: hidden;
}
#keyframes scroll {
0% {
transform: translateY(600%);
color: red;
}
50% {
transform: translateY(-200%);
color: blue;
}
}
.infobar p {
position: absolute;
width: 100%;
overflow: hidden;
display: inline-block;
animation-name: scroll;
animation-duration: 40s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
<div class="infobar">
<p>
Infobar test
<p>
</div>
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 6 years ago.
Improve this question
I am playing around with this code on codepen and I am trying to place text, under the animated circle and centered in the viewport, but I cannot seem to find a way to do it. I have set background: yellow; on the text for visibility.
If you know why the solution works, it would be immensely helpful if you could explain it here for me to understand/learn.
Try this: https://codepen.io/Lansana/pen/ezvVYR
HTML:
<div class="spinner-wrapper">
<div class='spinner'>
<div class='quadrant'></div>
<div class='quadrant'></div>
<div class='quadrant'></div>
<div class='quadrant'></div>
</div>
<div class='text'>test</div>
</div>
CSS:
html,
body {
height: 90%;
}
body {
background: #c2c2c2;
display: flex;
align-items: center;
justify-content: center;
}
.text {
background: yellow;
text-align: center;
}
.spinner-wrapper {
width: auto;
height: auto;
position: relative;
}
.spinner {
width: 300px;
height: 300px;
min-width: 300px;
position: relative;
animation: spin 60s linear infinite;
//border-radius: 300px;
.quadrant {
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
//z-index: 10;
mix-blend-mode: multiply;
//opacity: .5;
&:after {
content: "";
color: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 100%;
}
&:nth-child(1) {
animation: slide_horiz_neg 12s linear alternate infinite;
&:after {
//mix-blend-mode: multiply;
//opacity: .5;
background: cyan;
}
}
&:nth-child(2) {
animation: slide_vert_neg 8s linear alternate infinite;
&:after {
//mix-blend-mode: multiply;
//opacity: .5;
background: yellow;
}
}
&:nth-child(3) {
animation: slide_horiz_pos 10s linear alternate infinite;
&:after {
//mix-blend-mode: multiply;
//opacity: .5;
background: magenta;
}
}
/* &:nth-child(4) {
// animation: slide_vert_pos 3.5s linear alternate infinite;
&:after {
mix-blend-mode: normal;
//opacity: .5;
background: #000000;
}
} */
}
}
#keyframes spin {
to {
transform: rotate(360deg);
}
}
#keyframes slide_vert_pos {
0% {
transform: translateY(0%);
}
100% {
transform: translateY(1%);
}
}
#keyframes slide_vert_neg {
0% {
transform: translateY(0%);
}
100% {
transform: translateY(-1%);
}
}
#keyframes slide_horiz_pos {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(1%);
}
}
#keyframes slide_horiz_neg {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(-1%);
}
}
I created a wrapper, which contains your spinner and the text.
The wrapper has an auto height/width, based on it's child elements.
The text can be positioned any way you want within that wrapper, and it is not effected at all by the spinner except for the order in which the two are placed within the dom.
if you use flex, then apply it on HTML so body can shrink on content. margin-left:-50%; will be efficient and can be used to center one element.
For vertical-align, you may use (either) display : inline-block/inline-table + vertical-align:middle in order to center 2 elements being side by sides.
basicly, your CSS template can become
html {
height: 90%;
background: #c2c2c2;
display: flex;
align-items: center;
justify-content: center;
}
body {margin:0;}
.text {
background: yellow;
display: inline-table;/* or inline-block to vertical align */
vertical-align: middle;
margin-left: -50%;/* body flex-child takes width of content, not window ;) */
position: relative;/* bring it up front , add z-index too if needed */
}
.spinner {
display: inline-block;/* not a flex-child anymore & float doesn't allow vertical-align */
vertical-align: middle;/* says itself */
width: 300px;
height: 300px;
min-width: 300px;
position: relative;
animation: spin 60s linear infinite;
}
... and render -> https://codepen.io/anon/pen/qNrxPQ
Modified your code you can have look at codepen
https://codepen.io/anon/pen/KMWZOM
HTML
<div class="wrapper">
<div class='spinner'>
<div class='quadrant'></div>
<div class='quadrant'></div>
<div class='quadrant'></div>
<div class='quadrant'></div>
</div>
<div class='text'>test</div>
</div>
CSS
html,
body {
height: 90%;
}
.wrapper{
position:relative;
margin:0 auto;
}
body {
background: #c2c2c2;
display: flex;
align-items: center;
justify-content: center;
}
.text {
position: absolute;
background: yellow;
top:50%;
left:50%;
}
.spinner {
width: 300px;
height: 300px;
min-width: 300px;
position: relative;
animation: spin 60s linear infinite;
//border-radius: 300px;
.quadrant {
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
//z-index: 10;
mix-blend-mode: multiply;
//opacity: .5;
&:after {
content: "";
color: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 100%;
}
&:nth-child(1) {
animation: slide_horiz_neg 12s linear alternate infinite;
&:after {
//mix-blend-mode: multiply;
//opacity: .5;
background: cyan;
}
}
&:nth-child(2) {
animation: slide_vert_neg 8s linear alternate infinite;
&:after {
//mix-blend-mode: multiply;
//opacity: .5;
background: yellow;
}
}
&:nth-child(3) {
animation: slide_horiz_pos 10s linear alternate infinite;
&:after {
//mix-blend-mode: multiply;
//opacity: .5;
background: magenta;
}
}
/* &:nth-child(4) {
// animation: slide_vert_pos 3.5s linear alternate infinite;
&:after {
mix-blend-mode: normal;
//opacity: .5;
background: #000000;
}
} */
}
}
#keyframes spin {
to {
transform: rotate(360deg);
}
}
#keyframes slide_vert_pos {
0% {
transform: translateY(0%);
}
100% {
transform: translateY(1%);
}
}
#keyframes slide_vert_neg {
0% {
transform: translateY(0%);
}
100% {
transform: translateY(-1%);
}
}
#keyframes slide_horiz_pos {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(1%);
}
}
#keyframes slide_horiz_neg {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(-1%);
}
}
You can also try this:
.text {
position: relative;
background: yellow;
right: 150px;
top: 200px;
}
Since your spinner's circumference was 300px, to center it directly below, I divided it by half and assigned that position to the text to center it as well as any number above 150px in order to settle below the circle. Remember, these positions act inverted. Right moves it left and so on.
I'm animating line with css3 from width:0 to width:100%. At the moment is moving from left to right, but I want to make it to start from right to left. Is this posible at all with keyframes?
here is my code
.content {
width: 400px;
height: 200px;
color: white;
cursor: pointer;
text-transform: uppercase;
padding-bottom: 20px;
position: relative;
background: #333;
}
.content .line {
height: 2px;
background: white;
position: absolute;
top: 10px;
-webkit-animation: dude .75s 1 forwards;
-moz-animation: dude .75s 1 forwards;
-o-animation: dude .75s 1 forwards;
animation: dude .75s 1 forwards;
}
#-webkit-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#-moz-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#-o-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
<div class="content">
<div class="line"></div>
</div>
See this FIDDLE
add
.content .line {
right: 0;
}
.content {
width: 400px;
height: 200px;
color: white;
cursor: pointer;
text-transform: uppercase;
padding-bottom: 20px;
position: relative;
background: #333;
}
.content .line {
height: 2px;
background: white;
position: absolute;
top: 10px;
right: 0;
-webkit-animation: dude .75s 1 forwards;
animation: dude .75s 1 forwards;
}
#-webkit-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
#keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
<div class="content">
<div class="line"></div>
</div>
Try to animate "left" property instead of width as your element already has position set to absolute.
#keyframes dude {
0% {
left: 100%;
}
100% {
left: 0;
}
}
FIDDLE
change animation-direction to reverse
animation: dude .75s 1 reverse;
I want the progress bar to go from 0% width to 50% width in 2 seconds. This is my code so far:
<style>
#progressbar {
background-color: #000000;
border-radius: 8px;
padding: 3px;
width: 400px;
}
#progressbar div {
background-color: #0063C6;
height: 10px;
border-radius: 5px;
animation:loadbar 2s;
-webkit-animation:loadbar 2s;
}
#keyframes loadbar {
0% {
width: 0%;
}
100% {
width: 50%;
}
#-webkit-keyframes loadbar {
0% {
width: 0%;
}
100% {
width: 50%;
}
}
</style>
<div id="progressbar">
<div></div>
</div>
but when I open the page the width is 100% instead of 50%. what have I done wrong?
Your loadbar animation was not closed. The animation should work now. I've also added a forwards keyword to only play the animation once.
#progressbar {
background-color: black;
border-radius: 8px;
padding: 3px;
width: 400px;
}
#progressbar div {
background-color: #0063C6;
height: 10px;
border-radius: 5px;
animation:loadbar 2s normal forwards ease-in-out;
-webkit-animation:loadbar 2s normal forwards ease-in-out;
}
#keyframes loadbar {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#-webkit-keyframes loadbar {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
Here's a Fiddle
#progressbar div {
background-color: #0063C6;
width: 50%;
height: 10px;
border-radius: 5px;
animation:loadbar 2s;
-webkit-animation:loadbar 2s;
}
#keyframes loadbar {
0% {
width: 0%;
}
100% {
width: 50%;
}
}
#-webkit-keyframes loadbar {
0% {
width: 0%;
}
100% {
width: 50%;
}
}
jsFiddle demo
Set the initial width to 0%
#progressbar div {
background-color: #0063C6;
height: 10px;
width:0%; /* ADD THIS <<< */
border-radius: 5px;
animation:loadbar 2s;
-webkit-animation:loadbar 2s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
Additionally, I added in the following..
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
If you want the animation to end in a forwards motion you need this... here is a demo demonstrating what would happen without it.. jsFiddle here