CSS design - rainbow - html

I want to create a rainbow using only CSS only. Below is an image of what is required.
Here is my code (so far):
* {
margin: 0;
padding: 0;
}
#r {
height: 80vw;
width: 80vw;
background-color: #f00;
position: absolute;
z-index: 1;
}
#o {
height: 76vw;
width: 76vw;
background-color: #fe6230;
position: absolute;
top: 2vw;
left: 2vw;
z-index: 2;
}
#y {
height: 72vw;
width: 72vw;
background-color: #fef600;
position: absolute;
top: 4vw;
left: 4vw;
z-index: 3;
}
#g {
height: 68vw;
width: 68vw;
background-color: #00bc00;
position: absolute;
top: 6vw;
left: 6vw;
z-index: 4;
}
#b {
height: 64vw;
width: 64vw;
background-color: #0048fe;
position: absolute;
top: 8vw;
left: 8vw;
z-index: 5;
}
#i {
height: 60vw;
width: 60vw;
background-color: #000083;
position: absolute;
top: 10vw;
left: 10vw;
z-index: 6;
}
#v {
height: 56vw;
width: 56vw;
background-color: #30009b;
position: absolute;
top: 12vw;
left: 12vw;
z-index: 7;
}
<div id="r">
</div>
<div id="o">
</div>
<div id="y">
</div>
<div id="g">
</div>
<div id="b">
</div>
<div id="i">
</div>
<div id="v">
</div>
The problem with my code is that I am unable to curve it (like in a real rainbow). I also need to hide half of this rainbow.

This could be done using a single div element with a :pseudo-element and box-shadow.
div {
position: relative;
width: 300px;
height: 150px;
background: white;
overflow: hidden;
transform: scale(2);
margin-left: 130px;
margin-top: -50px;
}
div:after {
position: absolute;
content: '';
width: 100px;
height: 100px;
top: 100px;
left: 50px;
border-radius: 50%;
box-shadow: 0 0 0 5px #4200AB, 0 0 0 10px #000095, 0 0 0 15px #00ABFF, 0 0 0 20px #00C800, 0 0 0 25px #FFF800, 0 0 0 30px #FF7642, 0 0 0 35px #E40000;
}
<div></div>
Example using vh / vw units.
Demo on CodePen
Looks awful in the snippet here because of the viewport ratio, better viewed on CodePen.
div {
position: relative;
width: 95vw;
height: 45vw;
overflow: hidden;
background: transparent;
transform: translate(-50vw, -16.666vw);
top: 8vw;
left: 50vw;
}
div:after {
position: absolute;
content: '';
width: 50%;
height: 100%;
top: 25vw;
left: 25vw;
border-radius: 50%;
box-shadow: 0 0 0 2vw #4200AB, 0 0 0 4vw #000095, 0 0 0 6vw #00ABFF, 0 0 0 8vw #00C800, 0 0 0 10vw #FFF800, 0 0 0 12vw #FF7642, 0 0 0 14vw #E40000;
}
body {
margin: 0;
}
<div></div>

Here is a slightly different approach using radial-gradient. The approach is pretty much self explanatory as the gradient background is applied in an elliptical manner with multiple color stops (one for each color + white at the beginning and end).
Note: The browser support is much better for box-shadow than it is for radial-gradients and hence the answer posted by chipChocolate.py is probably the best for now.
This one can also support vw/vh units and can adapt the appearance accordingly.
.rainbow {
height: 25vw;
width: 50vw;
background: -webkit-radial-gradient(50% 110%, ellipse, white 35%, violet 35%, violet 40%, indigo 40%, indigo 45%, blue 45%, blue 50%, green 50%, green 55%, yellow 55%, yellow 60%, orange 60%, orange 65%, red 65%, red 70%, white 70%);
background: -moz-radial-gradient(50% 110%, ellipse, white 35%, violet 35%, violet 40%, indigo 40%, indigo 45%, blue 45%, blue 50%, green 50%, green 55%, yellow 55%, yellow 60%, orange 60%, orange 65%, red 65%, red 70%, white 70%);
background: radial-gradient(ellipse at 50% 110%, white 35%, violet 35%, violet 40%, indigo 40%, indigo 45%, blue 45%, blue 50%, green 50%, green 55%, yellow 55%, yellow 60%, orange 60%, orange 65%, red 65%, red 70%, white 70%);
}
<div class="rainbow"></div>

I thought i'd add just some of the rainbow designs found while going through codepen for your inspiration (note I did not make these, it's more for reference than anything)
option 1
#import "http://fonts.googleapis.com/css?family=Racing+Sans+One";
#-moz-keyframes spin {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#rainbow {
height: 290px;
overflow: hidden;
margin: 0 auto;
position: relative;
width: 580px;
-moz-transition: height 500ms ease-in-out;
-webkit-transition: height 500ms ease-in-out;
transition: height 500ms ease-in-out;
}
#rainbow.reveal {
height: 600px;
}
#rainbow li {
position: absolute;
height: 100%;
text-indent: -9999px;
opacity: 0.8;
}
#rainbow .ribbon {
border-radius: 50%;
border-style: solid;
border-width: 40px;
position: absolute;
left: inherit;
top: inherit;
-moz-animation: spin;
-moz-animation-duration: 2s;
-moz-animation-timing-function: ease-in-out;
-moz-animation-iteration-count: infinite;
-moz-animation-direction: alternate;
-moz-animation-fill-mode: forwards;
-webkit-animation: spin;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-fill-mode: forwards;
animation: spin;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-fill-mode: forwards;
}
#rainbow .red {
left: 0;
top: 0;
}
#rainbow .red .ribbon {
border-color: red;
height: 500px;
width: 500px;
clip: rect(0px, 580px, 290px, 0px);
-moz-animation-delay: 0s;
-webkit-animation-delay: 0s;
animation-delay: 0s;
}
#rainbow .orange {
left: 20px;
top: 20px;
}
#rainbow .orange .ribbon {
border-color: orange;
height: 420px;
width: 420px;
clip: rect(0px, 500px, 250px, 0px);
-moz-animation-delay: 1s;
-webkit-animation-delay: 1s;
animation-delay: 1s;
}
#rainbow .yellow {
left: 40px;
top: 40px;
}
#rainbow .yellow .ribbon {
border-color: yellow;
height: 340px;
width: 340px;
clip: rect(0px, 420px, 210px, 0px);
-moz-animation-delay: 2s;
-webkit-animation-delay: 2s;
animation-delay: 2s;
}
#rainbow .green {
left: 60px;
top: 60px;
}
#rainbow .green .ribbon {
border-color: green;
height: 260px;
width: 260px;
clip: rect(0px, 340px, 170px, 0px);
-moz-animation-delay: 3s;
-webkit-animation-delay: 3s;
animation-delay: 3s;
}
#rainbow .blue {
left: 80px;
top: 80px;
}
#rainbow .blue .ribbon {
border-color: blue;
height: 180px;
width: 180px;
clip: rect(0px, 260px, 130px, 0px);
-moz-animation-delay: 4s;
-webkit-animation-delay: 4s;
animation-delay: 4s;
}
#rainbow .indigo {
left: 100px;
top: 100px;
}
#rainbow .indigo .ribbon {
border-color: indigo;
height: 100px;
width: 100px;
clip: rect(0px, 180px, 90px, 0px);
-moz-animation-delay: 5s;
-webkit-animation-delay: 5s;
animation-delay: 5s;
}
#rainbow .violet {
left: 120px;
top: 120px;
}
#rainbow .violet .ribbon {
border-color: violet;
height: 20px;
width: 20px;
clip: rect(0px, 100px, 50px, 0px);
-moz-animation-delay: 6s;
-webkit-animation-delay: 6s;
animation-delay: 6s;
}
.cta {
cursor: pointer;
color: #622AF0;
font-family: 'Racing Sans One', cursive;
font-size: 18px;
display: block;
text-align: center;
margin-bottom: 5px;
}
body {
background: #DFFAFF;
}
<ul id="rainbow">
<li class="red">
<strong class="ribbon">Red</strong>
</li>
<li class="orange">
<strong class="ribbon">Orange</strong>
</li>
<li class="yellow">
<strong class="ribbon">Yellow</strong>
</li>
<li class="green">
<strong class="ribbon">Green</strong>
</li>
<li class="blue">
<strong class="ribbon">Blue</strong>
</li>
<li class="indigo">
<strong class="ribbon">Indigo</strong>
</li>
<li class="violet">
<strong class="ribbon">Violet</strong>
</li>
</ul>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
option 2
body {
background-color: #A7BACB;
margin: 0;
padding: 0;
}
html {
position: relative;
height: 100%;
background: #F9FEFF;
}
.rainbow {
width: 500px;
height: 240px;
margin: 20% auto 0 auto;
position: absolute;
left: 50%;
margin-left: -250px;
bottom:0;
}
.rainbow p {
text-indent: -9000px;
margin: 0;
position: absolute;
bottom: 0;
width: 100%;
-webkit-border-top-left-radius: 600px 560px;
-webkit-border-top-right-radius: 600px 560px;
-moz-border-radius-topleft: 600px 560px;
-moz-border-radius-topright: 600px 560px;
}
.rainbow p:nth-child(1),
.rainbow .r {
background-color: #FF0000; /* red */
height: 240px;
width: 500px;
}
.rainbow p:nth-child(2),
.rainbow .o {
background-color: #FF9900; /* orange */
height: 220px;
width: 460px;
left: 20px;
}
.rainbow p:nth-child(3),
.rainbow .y {
background-color: #FFFF00; /* yellow */
height: 200px;
width: 420px;
left: 40px;
}
.rainbow p:nth-child(4),
.rainbow .g {
background-color: #2ECE0C;/* green */
height: 180px;
width: 380px;
left: 60px;
}
.rainbow p:nth-child(5),
.rainbow .b {
background-color: #0000FF; /* blue */
height: 160px;
width: 340px;
left: 80px;
}
.rainbow p:nth-child(6),
.rainbow .i {
background-color: #6600FF; /* indigo */
height: 140px;
width: 300px;
left: 100px;
}
.rainbow p:nth-child(7),
.rainbow .v {
background-color: #8B00FF; /* violet */
height: 120px;
width: 260px;
left: 120px;
}
.rainbow p:nth-last-of-type(1),
.rainbow p:last-child {
background-color: #F9FEFF;
height: 100px;
width: 220px;
left: 140px;
}
<div class="rainbow">
<p class="r">red</p>
<p class="o">orange</p>
<p class="y">yellow</p>
<p class="g">green</p>
<p class="b">blue</p>
<p class="i">indigo</p>
<p class="v">violet</p>
<p>the end</p>
</div>
option 3 (box shadow idea)
div {
width: 50%;
margin: 40px auto;
text-align: center;
}
.rainbow {
background-color: #000;
display: block;
font-family: Georgia;
font-size: 14px;
padding: 80px;
margin-top: 160px;
border-radius: 80px;
box-shadow:
0 0 0 20px violet,
0 0 0 40px indigo,
0 0 0 60px blue,
0 0 0 80px green,
0 0 0 100px yellow,
0 0 0 120px orange,
0 0 0 140px red;
width: 0;
}
<div>
<a class="rainbow"></a>
</div>
option 4 (using border colors)
body{
background: #9ecdef;
}
.rainbow {
width: 600px;
height: 300px;
overflow: hidden;
position: absolute;
top: calc(50% - 150px);
left: calc(50% - 300px);
}
.border{
border-style: solid;
border-width: 10px;
border-left-color: transparent;
border-bottom-color: transparent;
border-radius: 50%;
}
.red {
width: calc(100% - 20px);
height: calc(200% - 20px);
border-top-color: #f00;
border-right-color: #f00;
animation: rotate 2s ease-in-out;
-webkit-animation: rotate 2s ease-in-out;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.size{
width: calc(100% - 20px);
height: calc(100% - 20px);
}
.orange{
border-top-color: #ff4500;
border-right-color: #ff4500;
}
.yellow{
border-top-color: #ff0;
border-right-color: #ff0;
}
.green{
border-top-color: #0f0;
border-right-color: #0f0;
}
.blue{
border-top-color: #00f;
border-right-color: #00f;
}
.cyan{
border-top-color: #0ff;
border-right-color: #0ff;
}
.purple{
border-top-color: #8a2be2;
border-right-color: #8a2be2;
}
#keyframes rotate {
from{-webkit-transform: rotate(-225deg);}
to{-webkit-transform: rotate(-45deg);}
}
#-webkit-keyframes rotate {
from{-webkit-transform: rotate(-225deg);}
to{-webkit-transform: rotate(-45deg);}
}
<div class="rainbow">
<div class="red border">
<div class="orange border size">
<div class="yellow border size">
<div class="green border size">
<div class="blue border size">
<div class="cyan border size">
<div class="purple border size">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Related

I can't make the 3/4 circle and i have to use one div only so how can i make it as the example in the link below

here is the shape i want to do enter link description here
P.S.I am still learning the front-end stuff so could you pls help me with this assignment.
Here is the HTML code <div>Elzero</div>
here is the CSS code i tried to do with
* {
box-sizing: border-box;
}
div {
width: 200px;
height: 200px;
background-color: #eee;
margin: 80px auto;
color: black;
font-size: 50px;
font-weight: bold;
text-align: center;
line-height: 200px;
border-radius: 50%;
}
::after {
content: "";
width: 200px;
height: 200px;
background-color: #03a9f4;
margin: 80px auto;
border-radius: 50%;
position: absolute;
transform: translate(-190px, -80px);
z-index: -1;
}
::before {
content: "";
width: 200px;
height: 200px;
background-color: #e91e63;
margin: 80px auto;
border-radius: 50%;
position: absolute;
top: 0px;
z-index: -2;
}
div:hover {
transition: all 0.5s;
transform: rotate(180deg);
}
As you are constrained to use just one div, this snippet builds on your idea of having the pseudo elements but creating them with conic-gradient backgrounds and the 'main' div having the light gray circular background created using a radial gradient. That way it creates these 3 shapes.
and overlays them to give the impression of 3/4 circles. It then uses CSS animation to rotate them on hover.
Obviously you will want to play with the dimensions, the animations timings and directions to get exactly what you want but this should give a start.
* {
box-sizing: border-box;
}
div {
width: 200px;
height: 200px;
background-image: radial-gradient(#eee 0 55%, transparent 55% 100%);
margin: 80px auto;
color: black;
font-size: 50px;
font-weight: bold;
text-align: center;
line-height: 200px;
border-radius: 50%;
position: relative;
}
div::after {
content: "";
width: 200px;
height: 200px;
border-radius: 50%;
position: absolute;
top: 0;
left: 0;
z-index: -2;
background-image: conic-gradient(#03a9f4 0deg 45deg, white 45deg 135deg, #03a9f4 135deg 360deg);
}
div::before {
content: "";
width: calc(100% - 10%);
height: calc(100% - 10%);
position: absolute;
border-radius: 50%;
position: absolute;
top: 5%;
left: 5%;
z-index: -1;
background-image: conic-gradient(#e91e63 0, #e91e63 225deg, white 225deg, white 315deg, #e91e63 315deg, #e91e63 360deg);
}
div:hover::after {
animation: rot .4s linear;
}
div:hover::before {
animation: rot .4s linear;
animation-delay: .1s;
animation-direction: reverse;
}
#keyframes rot {
0% {
transform: rotate(0);
}
25% {
transform: rotate(180deg);
}
50% {
transform: rotate(180deg);
}
75% {
transform: rotate(0);
}
100% {}
}
<div>Elzero
</div>
also here is example in less:
https://codepen.io/nikitahl/pen/XooBXd
if you want to use css here is a converter:
https://jsonformatter.org/less-to-css

SCSS Animation Does Not Work For Some Reason

So the main issue here is that when I load the web page, the animation does not move and is static. Additionally, I wanted the text to be on the top of the .star; however, despite many attempts of changing the order of the code, that does not seem to work either.
I have used multiple different CSS to SCSS converters to convert this code; however, it does not seem to work at all. I have tried different ways to counteract the issue as well as doing a lot of research.
Visual Representation:
Screenshot
OR... You may also check my website directly!
SCSS Code:
div.info_box {
width: 85%;
margin-top: -50px;
padding: 30px;
position: relative;
z-index: 1;
// text-align: center;
background: linear-gradient(125deg, #00103a 0%, #3e5f77 100%);
color: #fff;
// margin-top: $section-padding;
border-radius: $border-radius-sections;
.info_title {
text-align: left;
// max-width: 75%;
margin: 0 auto;
color: #fff;
h1 {
color: white;
font-size: 230%;
}
h2,
h3,
article {
color: white;
font-size: 130%;
}
}
// Animations
#keyframes tail {
0% {
width: 0;
}
30% {
width: 100px;
}
100% {
width: 0;
}
}
#keyframes shining {
0% {
width: 0;
}
50% {
width: 30px;
}
100% {
width: 0;
}
}
#keyframes shooting {
0% {
transform: translateX(0);
}
100% {
transform: translateX(320px);
}
}
.star {
position: absolute;
top: 50%;
left: 50%;
width: 180px;
background: linear-gradient(-45deg, #5f91ff, rgba(0, 0, 255, 0));
filter: drop-shadow(0 0 6px #699bff);
animation: tail 3000ms ease-in-out infinite shooting 3000ms ease-in-out infinite;
&::before {
position: absolute;
content: "";
top: calc(50% - 1px);
right: 0;
height: 2px;
width: 30px;
background: linear-gradient(-45deg, rgba(0, 0, 255, 0), #5f91ff, rgba(0, 0, 255, 0));
border-radius: 100%;
transform: translateX(50%) rotateZ(45deg);
}
&::after {
position: absolute;
content: "";
top: calc(50% - 1px);
right: 0;
height: 2px;
width: 30px;
background: linear-gradient(-45deg, rgba(0, 0, 255, 0), #5f91ff, rgba(0, 0, 255, 0));
border-radius: 100%;
transform: translateX(50%) rotateZ(45deg);
transform: translateX(50%) rotateZ(-45deg);
}
&:nth-child(1) {
top: calc(50% - 200px);
left: calc(50% - 300px);
animation-delay: 650ms;
&::before {
animation-delay: 650ms;
}
&::after {
animation-delay: 650ms;
animation-delay: 150ms;
animation-delay: 1600ms;
animation-delay: 4700ms;
animation-delay: 2100ms;
}
}
&:nth-child(2) {
top: calc(50% - -50px);
left: calc(50% - 190px);
animation-delay: 150ms;
&::before {
animation-delay: 150ms;
}
}
&:nth-child(3) {
top: calc(50% - -90px);
left: calc(50% - 200px);
animation-delay: 1600ms;
&::before {
animation-delay: 1600ms;
}
}
&:nth-child(4) {
top: calc(50% - 50px);
left: calc(50% - 250px);
animation-delay: 4700ms;
&::before {
animation-delay: 4700ms;
}
}
&:nth-child(5) {
top: calc(50% - -190px);
left: calc(50% - 200px);
animation-delay: 2100ms;
&::before {
animation-delay: 2100ms;
}
}
}
HTML Code:
<div style="align-self: flex-start; justify-self: center;" class="info_box">
<div class="info_title">
<h1><b>Welcome Nerds 🤓</b></h1>
<h3><i>Currently in a near-rectilinear halo orbit.</i><br><br>My name is <b>John</b>. I am a
<b>digital
creator</b>, a self-employed <b>software engineer</b>, a <b>cinematographer</b>,
and
most importantly, a full-time <b>high school student</b>.
</h3>
<br>Learn more about John 👊
</div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
</div>
There are at least 2 problems with this.
The first is that the animtion definition under .star is invalid:
animation: tail 3000ms ease-in-out infinite shooting 3000ms ease-in-out infinite;
You can see this if you go to your browser's dev tools inspect facility - it reports the property value as invalid. (You need to set a list).
The second is that the keyframes definitions seem to be nested but need to be brought out separately. (AFAIK the preprocessor doesn't spot this and do it for you).

Can not get CSS animation to work in Shopify

I cannot get my animation to animate in my Shopify page. As you can see it is static and not moving how it should. I have decompiled the SASS to CSS, I have no errors in the inspect element tool. I am using the exact code from Codepen, I have the CSS in the theme.scss.liquid folder. So I'm stumped on why it's not working any help is appreciated.
https://codepen.io/marvindanig/pen/avLRJz
html
<div class="toy-train">
<div class="engine">
<div class="window">
<div class="engine-main">
<div class="smokes">
<span></span>
</div>
</div>
</div>
<div class="engine-body">
<div class="wheels">
<div class="big-wheel"></div>
<div class="normal-wheel"></div>
</div>
</div>
</div>
<div class="locomotive">
<div class="trash"></div>
<div class="wheels">
<div class="normal-wheel"></div>
<div class="normal-wheel"></div>
</div>
</div>
<div class="tracks">
<span></span>
<span></span>
</div>
</div>
CSS
#about-us{
body {
background: linear-gradient(90deg, #1A2980 10%, #26D0CE 90%);
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
.toy-train {
position: relative;
width: 11vw;
}
.engine {
float: right;
position: relative;
}
.window {
height: 2.8vw;
width: 3vw;
background-color: #194488;
position: relative;
border: .3vw solid #000;
}
.window:before,
.window:after {
content: "";
position: absolute;
left: 50%;
border: .3vw solid #000;
}
.window:before {
height: .7vw;
background-color: #F82510;
width: 4.5vw;
margin-top: -1.3vw;
margin-left: -2.6vw;
border-radius: .8vw;
}
.window:after {
margin-left: -.8vw;
margin-top: .3vw;
border-radius: 50%;
height: 1.1vw;
width: 1.1vw;
background-color: #fff;
}
.engine-main {
height: 1vw;
width: 3.5vw;
border: .3vw solid #000;
background-color: #3D9A01;
position: absolute;
border-radius: 0 .8vw .8vw 0;
right: -4.1vw;
bottom: -.3vw;
}
.engine-main:before {
content: "";
height: 1vw;
width: .8vw;
background-color: #000;
position: absolute;
top: -1.1vw;
left: .4vw;
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
border-radius: 50% 50% 50% 50% / 90% 90% 40% 40%;
}
.engine-main:after {
content: "";
height: 1.2vw;
width: .8vw;
position: absolute;
display: block;
right: .5vw;
top: -1.8vw;
border-radius: 50% 50% 50% 50% / 90% 90% 40% 40%;
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
z-index: -1;
background-color: #194488;
border: .3vw solid #000;
}
.engine-body {
height: 1.7vw;
width: 7.5vw;
position: absolute;
left: -.2vw;
top: 3.0vw;
background-color: #F69F00;
border: .3vw solid #000;
border-radius: .5vw;
}
.engine-body .big-wheel {
top: .3vw;
left: .2vw;
}
.engine-body .normal-wheel {
left: 4.5vw;
top: .5vw;
}
.engine-body:before {
content: "";
position: absolute;
height: .5vw;
width: .5vw;
left: -1.1vw;
bottom: .2vw;
z-index: -1;
background-color: #fff;
border-radius: 50%;
border: .3vw solid #000;
}
.wheels > div {
position: absolute;
background-color: #F82510;
border-radius: 50%;
border: .3vw solid #000;
-webkit-animation: wheel-rotate 1s linear infinite;
animation: wheel-rotate 1s linear infinite;
}
.wheels > div:before {
content: "";
position: absolute;
width: 100%;
border-bottom: .1vw solid #000;
top: 50%;
margin-top: -.1vw;
}
.wheels > div:after {
content: "";
height: .8vw;
width: .8vw;
position: absolute;
background-color: #000;
border-radius: 50%;
left: 50%;
top: 50%;
margin-left: -.4vw;
margin-top: -.4vw;
}
.wheels .big-wheel {
width: 2.2vw;
height: 2.2vw;
-webkit-animation-delay: -0.3s;
animation-delay: -0.3s;
}
.wheels .normal-wheel {
height: 2.0vw;
width: 2.0vw;
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.locomotive {
height: 3.5vw;
width: 6.0vw;
border: .3vw solid #000;
background-color: #F69F00;
border-radius: .5vw;
position: relative;
float: left;
margin-top: 1.3vw;
}
.locomotive:before {
content: "";
width: 100%;
background: linear-gradient(to right, #000000 0%, #000000 8%, #f69f00 8%, #f69f00 15%, #000000 15%, #000000 28%, #000000 34%, #f69f00 34%, #f69f00 65%, #000000 65%, #000000 65%, #000000 100%);
height: .3vw;
position: absolute;
top: .6vw;
left: 0;
}
.locomotive:after {
content: "";
width: 100%;
background: linear-gradient(to right, #000000 0%, #000000 24%, #f69f00 24%, #f69f00 65%, #f69f00 65%, #000000 65%, #000000 85%, #f69f00 85%, #f69f00 90%, #000000 90%, #000000 100%);
height: .3vw;
position: absolute;
top: 1.4vw;
left: 0;
}
.locomotive .wheels > div {
top: 2.2vw;
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.locomotive .wheels > div:first-child {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.locomotive .normal-wheel:first-of-type {
left: .2vw;
}
.locomotive .normal-wheel:last-of-type {
right: .2vw;
}
.locomotive .trash {
height: 3.5vw;
width: 5.0vw;
position: absolute;
top: -1.8vw;
border: .3vw solid #000;
background-color: #3D9A01;
border-radius: 50%;
left: .2vw;
z-index: -1;
}
.tracks {
position: relative;
width: 20vw;
bottom: -1vw;
overflow: hidden;
height: .3vw;
}
.tracks span {
display: inline;
height: .3vw;
width: 20vw;
position: absolute;
left: 20vw;
background: linear-gradient(to right, black 0%, black 30%, transparent 30%, transparent 39%, black 39%, black 61%, black 65%, transparent 65%, transparent 70%, black 71%, black 100%);
-webkit-animation: track 2s linear infinite;
animation: track 2s linear infinite;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.tracks span:nth-child(2) {
-webkit-animation-delay: -1s;
animation-delay: -1s;
}
.smokes:before,
.smokes:after,
.smokes span:before {
display: block;
content: "";
height: .8vw;
width: .8vw;
background-color: #fff;
border-radius: 50%;
position: absolute;
right: .8vw;
top: 1.5vw;
z-index: -1;
}
.smokes:before {
-webkit-animation: smoke 1s linear infinite;
animation: smoke 1s linear infinite;
}
.smokes span:before {
-webkit-animation: smoke 1s linear infinite;
animation: smoke 1s linear infinite;
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.smokes:after {
-webkit-animation: smoke 1s linear infinite;
animation: smoke 1s linear infinite;
-webkit-animation-delay: -0.3s;
animation-delay: -0.3s;
}
#-webkit-keyframes smoke {
100% {
top: -5vw;
opacity: 0.5;
}
}
#keyframes smoke {
100% {
top: -5vw;
opacity: 0.5;
}
}
#-webkit-keyframes wheel-rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes wheel-rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes track {
100% {
left: -20vw;
}
}
#keyframes track {
100% {
left: -20vw;
}
}
}
Just close the first selector or remove it:
#about-us{ to #about-us{}
#about-us{}
body {
background: linear-gradient(90deg, #1A2980 10%, #26D0CE 90%);
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
.toy-train {
position: relative;
width: 11vw;
}
.engine {
float: right;
position: relative;
}
.window {
height: 2.8vw;
width: 3vw;
background-color: #194488;
position: relative;
border: .3vw solid #000;
}
.window:before,
.window:after {
content: "";
position: absolute;
left: 50%;
border: .3vw solid #000;
}
.window:before {
height: .7vw;
background-color: #F82510;
width: 4.5vw;
margin-top: -1.3vw;
margin-left: -2.6vw;
border-radius: .8vw;
}
.window:after {
margin-left: -.8vw;
margin-top: .3vw;
border-radius: 50%;
height: 1.1vw;
width: 1.1vw;
background-color: #fff;
}
.engine-main {
height: 1vw;
width: 3.5vw;
border: .3vw solid #000;
background-color: #3D9A01;
position: absolute;
border-radius: 0 .8vw .8vw 0;
right: -4.1vw;
bottom: -.3vw;
}
.engine-main:before {
content: "";
height: 1vw;
width: .8vw;
background-color: #000;
position: absolute;
top: -1.1vw;
left: .4vw;
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
border-radius: 50% 50% 50% 50% / 90% 90% 40% 40%;
}
.engine-main:after {
content: "";
height: 1.2vw;
width: .8vw;
position: absolute;
display: block;
right: .5vw;
top: -1.8vw;
border-radius: 50% 50% 50% 50% / 90% 90% 40% 40%;
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
z-index: -1;
background-color: #194488;
border: .3vw solid #000;
}
.engine-body {
height: 1.7vw;
width: 7.5vw;
position: absolute;
left: -.2vw;
top: 3.0vw;
background-color: #F69F00;
border: .3vw solid #000;
border-radius: .5vw;
}
.engine-body .big-wheel {
top: .3vw;
left: .2vw;
}
.engine-body .normal-wheel {
left: 4.5vw;
top: .5vw;
}
.engine-body:before {
content: "";
position: absolute;
height: .5vw;
width: .5vw;
left: -1.1vw;
bottom: .2vw;
z-index: -1;
background-color: #fff;
border-radius: 50%;
border: .3vw solid #000;
}
.wheels > div {
position: absolute;
background-color: #F82510;
border-radius: 50%;
border: .3vw solid #000;
-webkit-animation: wheel-rotate 1s linear infinite;
animation: wheel-rotate 1s linear infinite;
}
.wheels > div:before {
content: "";
position: absolute;
width: 100%;
border-bottom: .1vw solid #000;
top: 50%;
margin-top: -.1vw;
}
.wheels > div:after {
content: "";
height: .8vw;
width: .8vw;
position: absolute;
background-color: #000;
border-radius: 50%;
left: 50%;
top: 50%;
margin-left: -.4vw;
margin-top: -.4vw;
}
.wheels .big-wheel {
width: 2.2vw;
height: 2.2vw;
-webkit-animation-delay: -0.3s;
animation-delay: -0.3s;
}
.wheels .normal-wheel {
height: 2.0vw;
width: 2.0vw;
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.locomotive {
height: 3.5vw;
width: 6.0vw;
border: .3vw solid #000;
background-color: #F69F00;
border-radius: .5vw;
position: relative;
float: left;
margin-top: 1.3vw;
}
.locomotive:before {
content: "";
width: 100%;
background: linear-gradient(to right, #000000 0%, #000000 8%, #f69f00 8%, #f69f00 15%, #000000 15%, #000000 28%, #000000 34%, #f69f00 34%, #f69f00 65%, #000000 65%, #000000 65%, #000000 100%);
height: .3vw;
position: absolute;
top: .6vw;
left: 0;
}
.locomotive:after {
content: "";
width: 100%;
background: linear-gradient(to right, #000000 0%, #000000 24%, #f69f00 24%, #f69f00 65%, #f69f00 65%, #000000 65%, #000000 85%, #f69f00 85%, #f69f00 90%, #000000 90%, #000000 100%);
height: .3vw;
position: absolute;
top: 1.4vw;
left: 0;
}
.locomotive .wheels > div {
top: 2.2vw;
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.locomotive .wheels > div:first-child {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.locomotive .normal-wheel:first-of-type {
left: .2vw;
}
.locomotive .normal-wheel:last-of-type {
right: .2vw;
}
.locomotive .trash {
height: 3.5vw;
width: 5.0vw;
position: absolute;
top: -1.8vw;
border: .3vw solid #000;
background-color: #3D9A01;
border-radius: 50%;
left: .2vw;
z-index: -1;
}
.tracks {
position: relative;
width: 20vw;
bottom: -1vw;
overflow: hidden;
height: .3vw;
}
.tracks span {
display: inline;
height: .3vw;
width: 20vw;
position: absolute;
left: 20vw;
background: linear-gradient(to right, black 0%, black 30%, transparent 30%, transparent 39%, black 39%, black 61%, black 65%, transparent 65%, transparent 70%, black 71%, black 100%);
-webkit-animation: track 2s linear infinite;
animation: track 2s linear infinite;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.tracks span:nth-child(2) {
-webkit-animation-delay: -1s;
animation-delay: -1s;
}
.smokes:before,
.smokes:after,
.smokes span:before {
display: block;
content: "";
height: .8vw;
width: .8vw;
background-color: #fff;
border-radius: 50%;
position: absolute;
right: .8vw;
top: 1.5vw;
z-index: -1;
}
.smokes:before {
-webkit-animation: smoke 1s linear infinite;
animation: smoke 1s linear infinite;
}
.smokes span:before {
-webkit-animation: smoke 1s linear infinite;
animation: smoke 1s linear infinite;
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.smokes:after {
-webkit-animation: smoke 1s linear infinite;
animation: smoke 1s linear infinite;
-webkit-animation-delay: -0.3s;
animation-delay: -0.3s;
}
#-webkit-keyframes smoke {
100% {
top: -5vw;
opacity: 0.5;
}
}
#keyframes smoke {
100% {
top: -5vw;
opacity: 0.5;
}
}
#-webkit-keyframes wheel-rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes wheel-rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes track {
100% {
left: -20vw;
}
}
#keyframes track {
100% {
left: -20vw;
}
}
}
<div class="toy-train">
<div class="engine">
<div class="window">
<div class="engine-main">
<div class="smokes">
<span></span>
</div>
</div>
</div>
<div class="engine-body">
<div class="wheels">
<div class="big-wheel"></div>
<div class="normal-wheel"></div>
</div>
</div>
</div>
<div class="locomotive">
<div class="trash"></div>
<div class="wheels">
<div class="normal-wheel"></div>
<div class="normal-wheel"></div>
</div>
</div>
<div class="tracks">
<span></span>
<span></span>
</div>
</div>

How to make my strip inside an oval have waves in css?

I have an oval, and inside the oval, I have a strip that I need it to have waves
I have made this:
.strip {
content: "";
position: relative;
background: #4286f4;
z-index: 1;
width: 100%;
height: 100%;
bottom: 0%;
animation: wipe 8s cubic-bezier(0.9, 0.7, 0.8, 0.8) forwards;
animation-iteration-count: infinite;
}
#keyframes wipe {
from {
bottom: 0%;
}
to {
bottom: 100%;
}
}
.oval {
position: absolute;
background: #343434;
-moz-border-radius: 0 50% / 0 100%;
-webkit-border-radius: 0 50% / 0 100%;
border-radius: 150px;
height: 100px;
width: 80%;
overflow: hidden;
}
<div class="oval">
<div class="strip"></div>
</div>
How can i make that my strip have infinite wave animation?
You can try some repeated radial-gradient over a linear-graident to create the waves. Then you can simply animate the background-position and you can get rid of one DOM element.
#keyframes wipe {
from {
background-position:0 85px,0 120px;
}
to {
background-position:100px -45px,100px -20px;
}
}
.oval {
border-radius: 150px;
height: 100px;
width: 80%;
overflow: hidden;
background:
radial-gradient(circle at center,#4286f4 67%,transparent 67.5%)0 5px /50px 50px repeat-x,
linear-gradient(#343434,#343434)0 30px/100% 150% repeat-x;
background-color: #4286f4;
animation: wipe 8s cubic-bezier(0.9, 0.7, 0.8, 0.8) forwards;
animation-iteration-count: infinite;
}
<div class="oval">
</div>
If I understand correctly you want the wave to go up and down?
You can specify percentages instead of from and to as keyframes-selector
.strip {
content: "";
position: relative;
background: #4286f4;
z-index: 1;
width: 100%;
height: 100%;
bottom: 0%;
animation: wipe 8s cubic-bezier(0.9, 0.7, 0.8, 0.8) forwards;
animation-iteration-count: infinite;
}
#keyframes wipe {
0% {
bottom: 0%;
}
50% {
bottom: 100%;
}
100% {
bottom: 0%;
}
}
.oval {
position: absolute;
background: #343434;
-moz-border-radius: 0 50% / 0 100%;
-webkit-border-radius: 0 50% / 0 100%;
border-radius: 150px;
height: 100px;
width: 80%;
overflow: hidden;
}
<div class="oval">
<div class="strip"></div>
</div>

CSS Keyframe image appearing before it should

I am having a tough time figuring out why my image within my keyframe (of the star) is showing up before the 50% keyframe. Right now it is showing up almost immediately.
What can I do to make it show up when I am wanting it to (after 50%)?
body {
background-color: #F5F5F5;
color: #555;
height: 100vh;
width: 100%;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star-container {
background-color: green;
color: white;
width: 60%;
height: 80%;
margin: 10% auto;
text-align: justify;
position: relative;
}
.star {
width: 250px;
height: 250px;
text-align: justify;
-webkit-animation-name: star;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
animation-name: star;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
}
22%,
45% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
/*shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );
shape-padding: 10px;
/*transition: all 1s ease; */
/*-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );*/
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
/* Standard syntax */
#keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
}
22%,
45% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
/*shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );
shape-padding: 10px;
/*transition: all 1s ease; */
/*-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );*/
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
}
<div class="star-container">
<div class="star">
</div>
</div>
Reason:
As I had mentioned in my reply to your comment here, the problem is because there is no background image specified in any of the frames before the 50% keyframe. This means that the UA treats it like a gradual change of background image from 0% to 50%. But since there cannot be a intermediate state for image display, it appears at roughly half duration between 0% to 50% for an animation with linear timing function (for other timing functions like ease, ease-in, ease-out it would be a little before or after the mid way point but the logic is the same).
Demo as proof of above point:
In the below snippet, I have set the animation-timing-function to linear and have inserted frames to change the background-color to yellow at 25% mark. You'd see how the image now appears at the exact same time when the color changes to yellow. This is to prove the statement in first para.
body {
background-color: #F5F5F5;
color: #555;
height: 100vh;
width: 100%;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star-container {
background-color: green;
color: white;
width: 60%;
height: 80%;
margin: 10% auto;
text-align: justify;
position: relative;
}
.star {
width: 250px;
height: 250px;
text-align: justify;
-webkit-animation-name: star;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
animation-name: star;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-timing-function: linear;
}
#keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
}
22% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
25% {
background-color: yellow;
}
45% {
background-color: yellow;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
}
49% {
background-color: yellow;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
}
50%,
100% {
/*shape-inside: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );
shape-padding: 10px;
/*transition: all 1s ease; */
/*-webkit-clip-path: polygon(125px 0, 175px 85px, 250px 90px, 190px 160px, 225px 250px, 125px 210px, 25px 250px, 60px 160px, 0px 90px, 75px 85px );*/
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
}
<div class="star-container">
<div class="star">
</div>
</div>
Solution:
The fix to this problem is to set background-image to none in all the frames before the 50% mark.
Demo: (Have removed all the vendor-prefixed versions to keep the snippet small)
body {
background-color: #F5F5F5;
color: #555;
height: 100vh;
width: 100%;
font-size: 1.1em;
font-family: 'Lato', sans-serif;
}
.star-container {
background-color: green;
color: white;
width: 60%;
height: 80%;
margin: 10% auto;
text-align: justify;
position: relative;
}
.star {
width: 250px;
height: 250px;
text-align: justify;
animation-name: star;
animation-duration: 4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#keyframes star {
0%, 21% {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
height: 50px;
width: 50px;
border-radius: 50%;
background-image: none;
}
22%, 45% {
background-color: red;
position: absolute;
left: 50%;
top: 90%;
height: 50px;
width: 50px;
border-radius: 50%;
background-image: none;
}
49% {
background-color: red;
left: 0px;
top: 0px;
height: 50px;
width: 50px;
border-radius: 50%;
background-image: none;
}
50%,
100% {
background-image: url('http://optimumwebdesigns.com/images/star.png');
background-repeat: no-repeat;
background-size: 100%;
height: 50px;
width: 50px;
}
}
<div class="star-container">
<div class="star">
</div>
</div>
Add animation-timing-function: linear to .star this will show the image exactly after 2s.