I have an animation which I want to play infinitely to catch the users attention.
It looks like this:
http://codepen.io/anon/pen/evdqeq
What I want to achieve is, that when the corner of the "paper" is folded, it will be paused for like 3 seconds. Then the paper corner should go back. Before restarting the animation I want a 5 second delay.
I have looked up for more information about css animations but there is nothing which really fits my needs.
Do I need to switch to JavaScript?
HTML
<div id="fpc_effect-back">
<div id="fpc_box">
<div id="fpc_content">
<img src="http://www.amboss-grimma.de/wp-content/uploads/2016/12/Katalog_Amboss.png">
</div>
<div id="fpc_corner-box">
<a id="fpc_page-tip" href="#">
<div id="fpc_corner-contents">
<div id="fpc_corner-button"><strong> </strong></div><div></a>
</div>
</div>
</div>
CSS
#fpc_effect-back {
background-color: #eeeef4;
width: 0;
font: 12pt arial,sans-serif,helvetica,verdana;
color: #666;
}
#fpc_effect-back * {
box-sizing: border-box;
}
#fpc_box {
width: 197px;
position: relative;
background-color: #FFF;
}
#fpc_content {
padding: 0px;
}
#fpc_content:before {
content:"";
width: 80px;
height: 0px;
float: right;
}
#fpc_page-tip:before, #fpc_page-tip:after {
background-color: #FFF;
position: absolute;
display: block;
z-index: 2;
border-top-right-radius: 60%;
width: 50%;
height: 50%;
content: "";
}
#fpc_page-tip:before {
right: 100%;
top: 0%;
background: -webkit-radial-gradient(-180% 200%, circle, rgba(255,255,255,0) 80%, rgba(0,0,0,.2) 100%);
}
#fpc_box:hover #fpc_page-tip:before {
border-right: solid 1px #fff;
}
#fpc_box div#fpc_corner-box:hover #fpc_page-tip:before {
border-right: solid 2px #fff;
}
#fpc_page-tip:after {
top: 100%;
right: 0%;
background: -webkit-radial-gradient(-250% 320%, circle, rgba(255,255,255,0) 80%, rgba(0,0,0,.2) 100%);
}
#fpc_box:hover #fpc_page-tip:after {
border-top: solid 1px #fff;
}
#fpc_box div#fpc_corner-box:hover #fpc_page-tip:after {
border-top: solid 2px #fff;
}
#fpc_corner-box {
height: 20px;
width: 20px;
right: 0;
top: 0;
position: absolute;
overflow: visible;
animation-name: paper-corner;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#fpc_box:hover #fpc_corner-box {
height: 65px;
width: 65px;
}
#fpc_box div#fpc_corner-box:hover {
}
#fpc_corner-box:before {
position: absolute;
top: 0;
right: 0;
content: "";
display: block;
width: 133%;
height: 133%;
}
#fpc_corner-contents:after {
position: absolute;
top: 0;
right: 0;
content: "";
background: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0) 37%, #DDD 62%, rgba(230, 230, 230, 0.1) 64%, rgba(255, 255, 255, 0) 67%), -webkit-radial-gradient(-50% 150%, circle, transparent 74%, rgba(0, 0, 0, 0.2) 74%, transparent 81%);
display: block;
width: 133%;
height: 133%;
}
#fpc_page-tip {
position: absolute;
top: 0;
right: 0;
content: "";
background: -webkit-linear-gradient(45deg, #ddd 17%, #dfdfdf 18%, #f5f5f5 30%, #f8f8f8 34%, #eee 39%, rgba(200,200,200,0) 41%);
display: block;
width: 100%;
height: 100%;
}
#fpc_corner-button {
position: absolute;
width: 7em;
top: 0;
right: 0;
background-color: none;
color: #fff;
font-family: Verdana, Geneva, sans-serif;
text-align: center;
padding: 8px 5px;
border-radius: 0px;
display: inline-block;
font-size: 11px;
}
#fpc_corner-contents {
width: 125%;
position: absolute;
display: block;
overflow: hidden;
-webkit-mask: -webkit-linear-gradient(45deg, transparent 49%, #000 53%);
top: 0;
right: 0;
height: 125%;
}
#fpc_corner-contents:before {
content: "";
position: absolute;
top: 0;
right: 0;
content: "";
display: block;
width: 100%;
height: 100%;
background-color: white; /* Match this background color to #fpc_effect-back */
}
#fpc_corner-box, #fpc_corner-contents, #fpc_page-tip {
-webkit-transition-property: all;
-webkit-transition-duration: .3s;
-webkit-transition-timing-function: cubic-bezier(0, 0.35, .5, 1.7);
}
#fpc_corner-button strong {
font-size: 13px;
font-weight: bold;
display: block;
}
#keyframe paper-corner{
from {height: 20px; width: 20px;}
to {height: 65px; width: 65px;}
}
#-moz-keyframes paper-corner {
from {
height:20px;
width:20px
}
to {
height:65px;
width:65px;
}
}
#-webkit-keyframes paper-corner {
from {
height:20px;
width:20px
}
to {
height:65px;
width:65px;
}
}
#keyframes paper-corner {
from {
height:20px;
width:20px
}
to {
height:65px;
width:65px;
}
}
to get the 5 second delay you need to add animation-delay:5s; to #fpc_corner-box or you can set the animation-duration: 8s;
and for the pause you can somehow achieve it using % in the animation like so:
#keyframes paper-corner {
0% {
height:20px;
width:20px
}
50% {
height:20px;
width:20px
}
60% {
height:65px;
width:65px;
}
90% {
height:65px;
width:65px;
}
100% {
height:20px;
width:20px;
}
}
Codepen demo
As i understand you can use `
setTimeout(function(){
$('#fpc_corner-box').css('animation','paper-corner 2s 1');
}, 5000); // 5000 in ms so it is 5 seconds
`
Put a longer animation-duration and add more keyframes. 0% and 100% are assumed. so it's not necessary to define them.
#fpc_corner-box {
height: 20px;
width: 20px;
right: 0;
top: 0;
position: absolute;
overflow: visible;
animation-name: paper-corner;
animation-duration: 10s; /**/
animation-iteration-count: infinite;
}
#keyframes paper-corner {
10% {
height: 65px;
width: 65px;
}
40% {
height: 65px;
width: 65px;
}
50% {
height: 20px;
width: 20px;
}
}
when the corner of the "paper" is folded, it will be paused for like 3
seconds. Then the paper corner should go back. Before restarting the
animation I want a 5 second delay.
So in total you have 3 + 5 = 8 i.e. an 8-second animation.
Easiest way would be to divide your entire animation into these 8 parts. For convenience sake, let's say 10-second animation.
First, make the animation-duration: 10s; i.e. the entire length.
Next, divide 100 by 10 and you get 10% intervals.
Now, you want a 3-second delay while starting. So, that means from 0% to 30% there is no animation. Where each 10% denotes a 1s (we divided into these chunks above). So no change in height/width.
So, your key-frames would look like this:
#keyframes paper-corner {
0% { height: 0px; width: 0px; }
30% { height: 0px; width: 0px; }
}
Next, you want end of the animation to stay for 5 seconds. Apply the same mechanism, but this time from the end. So, starting from 100% stepping 10% for each 1-second, you reach to 50% for 5-seconds. This means from 50% to 100% there is no change with width/height which is the end size.
So, your key-frames would now look like this:
#keyframes paper-corner {
0% { height: 0px; width: 0px; }
30% { height: 0px; width: 0px; }
50% { height: 65px; width: 65px; }
100% { height: 65px; width: 65px; }
}
Putting it all together in a Fiddle: https://jsfiddle.net/abhitalks/ntgtaber/
Snippet:
#fpc_effect-back {
background-color: #eeeef4;
width: 0;
font: 12pt arial, sans-serif, helvetica, verdana;
color: #666;
}
#fpc_effect-back * {
box-sizing: border-box;
}
#fpc_box {
width: 197px;
position: relative;
background-color: #FFF;
}
#fpc_content {
padding: 0px;
}
#fpc_content:before {
content: "";
width: 80px;
height: 0px;
float: right;
}
#fpc_page-tip:before,
#fpc_page-tip:after {
background-color: #FFF;
position: absolute;
display: block;
z-index: 2;
border-top-right-radius: 60%;
width: 50%;
height: 50%;
content: "";
}
#fpc_page-tip:before {
right: 100%;
top: 0%;
background: -webkit-radial-gradient(-180% 200%, circle, rgba(255, 255, 255, 0) 80%, rgba(0, 0, 0, .2) 100%);
}
#fpc_box:hover #fpc_page-tip:before {
border-right: solid 1px #fff;
}
#fpc_box div#fpc_corner-box:hover #fpc_page-tip:before {
border-right: solid 2px #fff;
}
#fpc_page-tip:after {
top: 100%;
right: 0%;
background: -webkit-radial-gradient(-250% 320%, circle, rgba(255, 255, 255, 0) 80%, rgba(0, 0, 0, .2) 100%);
}
#fpc_box:hover #fpc_page-tip:after {
border-top: solid 1px #fff;
}
#fpc_box div#fpc_corner-box:hover #fpc_page-tip:after {
border-top: solid 2px #fff;
}
#fpc_corner-box {
height: 20px;
width: 20px;
right: 0;
top: 0;
position: absolute;
overflow: visible;
animation-name: paper-corner;
animation-duration: 10s;
animation-iteration-count: infinite;
}
#fpc_box:hover #fpc_corner-box {
height: 65px;
width: 65px;
}
#fpc_box div#fpc_corner-box:hover {}
#fpc_corner-box:before {
position: absolute;
top: 0;
right: 0;
content: "";
display: block;
width: 133%;
height: 133%;
}
#fpc_corner-contents:after {
position: absolute;
top: 0;
right: 0;
content: "";
background: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0) 37%, #DDD 62%, rgba(230, 230, 230, 0.1) 64%, rgba(255, 255, 255, 0) 67%), -webkit-radial-gradient(-50% 150%, circle, transparent 74%, rgba(0, 0, 0, 0.2) 74%, transparent 81%);
display: block;
width: 133%;
height: 133%;
}
#fpc_page-tip {
position: absolute;
top: 0;
right: 0;
content: "";
background: -webkit-linear-gradient(45deg, #ddd 17%, #dfdfdf 18%, #f5f5f5 30%, #f8f8f8 34%, #eee 39%, rgba(200, 200, 200, 0) 41%);
display: block;
width: 100%;
height: 100%;
}
#fpc_corner-button {
position: absolute;
width: 7em;
top: 0;
right: 0;
background-color: none;
color: #fff;
font-family: Verdana, Geneva, sans-serif;
text-align: center;
padding: 8px 5px;
border-radius: 0px;
display: inline-block;
font-size: 11px;
}
#fpc_corner-contents {
width: 125%;
position: absolute;
display: block;
overflow: hidden;
-webkit-mask: -webkit-linear-gradient(45deg, transparent 49%, #000 53%);
top: 0;
right: 0;
height: 125%;
}
#fpc_corner-contents:before {
content: "";
position: absolute;
top: 0;
right: 0;
content: "";
display: block;
width: 100%;
height: 100%;
background-color: white;
/* Match this background color to #fpc_effect-back */
}
#fpc_corner-box,
#fpc_corner-contents,
#fpc_page-tip {
-webkit-transition-property: all;
-webkit-transition-duration: .3s;
-webkit-transition-timing-function: cubic-bezier(0, 0.35, .5, 1.7);
}
#fpc_corner-button strong {
font-size: 13px;
font-weight: bold;
display: block;
}
#keyframes paper-corner {
0% { height: 0px; width: 0px; }
30% { height: 0px; width: 0px; }
50% { height: 65px; width: 65px; }
100% { height: 65px; width: 65px; }
}
<div id="fpc_effect-back">
<div id="fpc_box">
<div id="fpc_content">
<img src="http://www.amboss-grimma.de/wp-content/uploads/2016/12/Katalog_Amboss.png" />
</div>
<div id="fpc_corner-box">
<a id="fpc_page-tip" href="#">
<div id="fpc_corner-contents">
<div id="fpc_corner-button"></div>
</div>
</a>
</div>
</div>
</div>
Related
I want to make the following design:
I tried with :after and :before but it does not work. Here’s my current code:
.design {
background: #ea053a;
display: inline-block;
height: 155px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 228px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 55px;
margin-top: 100px;
width: 128px;
}
<div class="design"></div>
How could I leave it the same as the original design and with the following two properties?:
box-shadow: 0 1px 10px 0 rgba(0, 0, 0, 0.2);
background-image: linear-gradient(to bottom, #ea053a, #d0021b);
Here is an idea with skew transformation and drop-shadow filter. You simply need some extra element to correctly have the gradient. The trick is to invert the skew to keep the gradient direction correct (not needed if we deal with solid color)
.box {
width: 150px;
height: 150px;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box span {
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
}
.box span:first-of-type {
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}
.box span:last-of-type {
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
}
.box span::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, blue , red );
transform-origin: inherit;
}
.box span:first-of-type::before {
transform: skewY(-35deg);
}
.box span:last-of-type::before {
transform: skewY(35deg);
}
p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<span></span><span></span>
<p>29</p>
</div>
Here is how we can do with a left or right gradient. In this case we don't need extra elements because the skew will not affect the direction:
.box {
width: 150px;
height: 150px;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box:before,
.box:after{
content:"";
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
background:linear-gradient(to right,blue,red);
background-size:200% 100%;
}
.box:before{
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}
.box:after{
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
background-position:right;
}
p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<p>29</p>
</div>
And here is with an arbitrary gradient:
.box {
--g:linear-gradient(45deg,blue,red 60%,yellow); /* gradient coloration*/
width: 150px;
height: 150px;
margin:15px;
display:inline-block;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box span {
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
}
.box span:first-of-type {
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}
.box span:last-of-type {
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
}
.box span::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--g);
background-size:200% 100%;
transform-origin: inherit;
}
.box span:first-of-type::before {
transform: skewY(-35deg);
}
.box span:last-of-type::before {
transform: skewY(35deg);
background-position:right;
}
p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<span></span><span></span>
<p>29</p>
</div>
<div class="box" style="--g:linear-gradient(-62deg,blue,red 60%,yellow)">
<span></span><span></span>
<p>29</p>
</div>
Since each element is taking 50% of the width we make the background to be 200% to have its size as the main container then we adjust the position to create the illusion of one background. It's like each element will show half of the main background.
An optimized version using mask
.box {
width: 150px;
height: 150px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box > div {
height: 100%;
background: linear-gradient(35deg, blue, red);
-webkit-mask:
linear-gradient(#fff, #fff) top/100% 70%,
linear-gradient(to bottom right, #fff 49.5%, transparent 50%) bottom right/50% 30%,
linear-gradient(to bottom left, #fff 49.5%, transparent 50%) bottom left /50% 30%;
mask:
linear-gradient(#fff, #fff) top/100% 70%,
linear-gradient(to bottom right, #fff 49.5%, transparent 50%) bottom right/50% 30%,
linear-gradient(to bottom left, #fff 49.5%, transparent 50%) bottom left /50% 30%;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}
p {
margin: 0;
color: #fff;
font-size: 45px;
line-height: 100px;
text-align: center;
}
<div class="box">
<div>
<p>29</p>
</div>
</div>
Or clip-path
.box {
width: 150px;
height: 150px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box > div {
height: 100%;
background: linear-gradient(35deg, blue, red);
clip-path:polygon(0 0,100% 0,100% 70%,50% 100%,0 70%);
}
p {
margin: 0;
color: #fff;
font-size: 45px;
line-height: 100px;
text-align: center;
}
<div class="box">
<div>
<p>29</p>
</div>
</div>
You can use clip-path as I did. Here is my solution.
.design {
background: #ea053a;
-webkit-clip-path: polygon(50% 0%, 100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
clip-path: polygon(50% 0%, 100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
height: 155px;
width: 155px;
}
.month {
text-align:center;
padding: 1rem 0 .25rem 0;
color:#fff;
font-weight:bold;
font-size: 18px;
}
.day {
text-align: center;
font-size: 60px;
font-weight:bold;
color: #fff;
}
<div class="design">
<div class="month">Diciembre</div>
<div class="day">29</div>
</div>
If you change your CSS to the following minor changes, then you can achieve the result that you have expected:
.design {
background: #ea053a;
display: inline-block;
height: 100px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 180px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 0px;
margin-top: 100px;
width: 0;
}
Here is the working of the above CSS:
.design {
background: #ea053a;
display: inline-block;
height: 100px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 180px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 0px;
margin-top: 100px;
width: 0;
}
<div class="design">
</div>
Hope this was helpful.
My Fiddle
Change to (only changed lines listed, keep everything else as-is):
.design:before {
...
border-left: 114px solid transparent;
border-right: 114px solid transparent;
...
width: 0;
}
Here is my solution to add shadow and gradient to the shape
.design {
background: #ea053a;
display: inline-block;
height: 155px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 228px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.triangle {
position: absolute;
height: 100px;
top: 155px;
width: 228px;
-webkit-clip-path: polygon(49% 44%, 0% 100%, 100% 100%);
clip-path: polygon(49% 44%, 0% 100%, 100% 100%);
background-color: #ea053a;
transform: rotate(180deg);
}
<div class="design">
<div class="triangle">
</div>
</div>
The CSS animation here on my website is missing some features from the Codepen example such as the smoke and there is gaps in between some parts of the train. The code used is identical except I have to decompile the SASS to CSS before I put it into Shopify. And here is the Codepen link
body {
background: linear-gradient(90deg, #1A2980 10%, #26D0CE 90%);
height: 100vh;
width: 100vw;
display: -webkit-box;
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;
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%;
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;
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;
animation-delay: -0.3s;
}
.wheels .normal-wheel {
height: 2.0vw;
width: 2.0vw;
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;
animation-delay: -0.6s;
}
.locomotive .wheels>div:first-child {
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%);
animation: track 2s linear infinite;
animation-fill-mode: forwards;
}
.tracks span:nth-child(2) {
animation-delay: -1s;
}
.smokes:before,
.smokes:after,
.smokes span:before {
display: block;
content: "";
height: .8vw;
width: .8vw;
background-color: #e80404;
border-radius: 50%;
position: absolute;
right: .8vw;
top: 1.5vw;
z-index: -1;
}
.smokes:before {
animation: smoke 1s linear infinite;
}
.smokes span:before {
animation: smoke 1s linear infinite;
animation-delay: -0.6s;
}
.smokes:after {
animation: smoke 1s linear infinite;
animation-delay: -0.3s;
}
#keyframes smoke {
100% {
top: -5vw;
opacity: 0.5;
}
}
#keyframes wheel-rotate {
100% {
transform: rotate(360deg);
}
}
#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>
I have to make a div using HTML and CSS only but not using any background image with more than 4 corners.
How can I do it?
You can use pseudo-element and some css shape tricks to achieve this.
.folder {
width: 190px;
height: 110px;
background: #888;
position: relative;
overflow: hidden;
}
.folder:after {
content: "";
width: 100px;
border: 15px solid transparent;
position: absolute;
right: -15px;
border-top-color: #fff;
top:0;
}
<div class="folder"></div>
There are two examples of code: with CSS ( + animation ) and SVG.
With animation
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
position: relative;
width: 100%;
height: 100%;
background-color: #2196f3;
}
.page {
height: 100%;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-moz-box-align: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
}
.folder {
background-color: #d3eafd;
position: relative;
width: 92px;
height: 64px;
display: block;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
}
.folder-tab {
position: absolute;
height: 10px;
left: 0;
bottom: 100%;
display: block;
width: 40%;
border-top-left-radius: 8px;
background-color: inherit;
}
.folder-tab:after {
content: '';
position: absolute;
display: block;
top: 0;
left: calc(100% - 10px);
border-bottom: 10px solid #d3eafd;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.folder-icn {
padding-top: 12px;
width: 100%;
height: 100%;
display: block;
}
.downloading {
width: 30px;
height: 32px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
.custom-arrow {
width: 14px;
height: 14px;
position: absolute;
top: 0;
left: 50%;
margin-left: -7px;
background-color: #fff;
-webkit-animation-name: downloading;
-webkit-animation-duration: 1.5s;
-webkit-animation-iteration-count: infinite;
animation-name: downloading;
animation-duration: 1.5s;
animation-iteration-count: infinite;
}
.custom-arrow:after {
content: '';
position: absolute;
display: block;
top: 100%;
left: -9px;
border-top: 15px solid #fff;
border-left: 16px solid transparent;
border-right: 16px solid transparent;
}
.bar {
width: 30px;
height: 4px;
background-color: #fff;
margin: 0 auto;
}
#-webkit-keyframes downloading {
0% {
top: 0;
opacity: 1;
}
50% {
top: 110%;
opacity: 0;
}
52% {
top: -110%;
opacity: 0;
}
100% {
top: 0;
opacity: 1;
}
}
#keyframes downloading {
0% {
top: 0;
opacity: 1;
}
50% {
top: 110%;
opacity: 0;
}
52% {
top: -110%;
opacity: 0;
}
100% {
top: 0;
opacity: 1;
}
}
<div class="page">
<div class="folder">
<span class="folder-tab"></span>
<div class="folder-icn">
<div class="downloading">
<span class="custom-arrow"></span>
</div>
<div class="bar"></div>
</div>
</div>
</div>
SVG
<!DOCTYPE html>
<html>
<body>
<svg height="32px" version="1.1" viewBox="0 0 32 32" width="32px" xmlns="http://www.w3.org/2000/svg" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" xmlns:xlink="http://www.w3.org/1999/xlink"><title/><desc/><defs/><g fill="none" fill-rule="evenodd" id="Page-1" stroke="none" stroke-width="1"><g fill="#157EFB" id="icon-94-folder"><path d="M17,11 L15,7 L4.00276013,7 C2.89666625,7 2,7.88967395 2,8.991155 L2,27.008845 C2,28.1085295 2.89971268,29 3.99328744,29 L29.0067126,29 C30.1075748,29 31,28.1073772 31,27.0049107 L31,12.9950893 C31,11.8932319 30.1029399,11 28.9941413,11 L17,11 Z" id="folder"/></g></g>
</svg>
</body>
</html>
Helpful links:
More about SVG ( W3C )
The Shapes of CSS ( CSS-Tricks )
div {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(48% 13%, 100% 13%, 100% 60%, 100% 100%, 0 100%, 0 0, 29% 0);
clip-path: polygon(48% 13%, 100% 13%, 100% 60%, 100% 100%, 0 100%, 0 0, 29% 0);
}
/* Center the demo */
html, body { height: 100%; }
body {
display: flex;
justify-content: center;
align-items: center;
}
<div></div>
With only a single block level element, you may style a :before pseudo-element to create the slanted tab above the containing <div>.
div {
margin: 40px;
width: 150px;
height: 80px;
background: red;
position: relative;
padding: 10px;
color: #fff;
}
div:before {
content:"";
position: absolute;
left: 0;
top: -20px;
width: 70px;
height: 0;
border-bottom: 20px solid red;
border-right: 20px solid transparent;
}
<div>content</div>
N.b.: This should have a better support on older browsers (and IE) than using a clip-path solution.
Just another way of doing it using the "canvas" of HTML5:
<div>
<canvas id="cnv" height="200" width="400"></canvas>
<script>
var canvas = document.getElementById('cnv');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(100, 0);
ctx.lineTo(130, 25);
ctx.lineTo(200, 25);
ctx.lineTo(200, 125);
ctx.lineTo(0, 125);
ctx.closePath();
ctx.fillStyle = "gray";
ctx.fill();
}
</script>
</div>
You can achieve this using single element and two gradients (one gradient for rectangle, another is for tab):
div {
width: 280px;
height: 200px;
background: linear-gradient(to bottom, transparent 31px, #656d78 31px),
linear-gradient(-135deg, transparent 32%, #656d78 32%);
}
<div></div>
Also this can be achieved via single gradient (for tab) using pseudoelement:
div {
width: 280px;
height: 169px;
background-color: #656d78;
margin-top: 39px;
position: relative;
}
div:after {
content: "";
position: absolute;
top: -31px;
left: 0;
width: 100%;
height: 31px;
background: linear-gradient(-135deg, transparent 50%, #656d78 50%);
}
<div></div>
If you can insert code, you could use a SVG graphic.
If not, you could draw the vector graphic css clip-path as the answer above.
There are some generators, here is one I've found
Another option is to use at least 3 divs, skew one using css transform in one of them and locating each one using relative os absolute positioning.
You can make polygon's div using CSS.
.myDiv {
-webkit-clip-path: polygon(48% 16%, 100% 16%, 100% 100%, 0% 100%, 0 0, 32% 0);
clip-path: polygon(48% 16%, 100% 16%, 100% 100%, 0% 100%, 0 0, 32% 0);
}
Or you can create any type of polygon shape (online) using this website
https://www.cssportal.com/css-clip-path-generator/
Fiddle: https://jsfiddle.net/0qqnvrdg/
HTML:
<div class="loading"></div>
CSS:
body {
background: #0d8aa5;
}
.loading {
position: absolute;
left: 50%;
top: 25%;
/*margin: -60px 0 0 -60px;*/
background: #fff;
width: 200px;
height: 200px;
border-radius: 100%;
border: 10px solid #19bee1;
}
.loading:after {
content: '';
background: trasparent;
width: 140%;
height: 140%;
position: absolute;
border-radius: 100%;
top: -20%;
left: -20%;
opacity: 0.7;
box-shadow: rgba(255, 255, 255, 0.6) -4px -5px 3px -3px;
animation: rotate 2s infinite linear;
}
#keyframes rotate {
0% {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(360deg);
}
}
.loading:before {
background-image: url('http://i.stack.imgur.com/UTnLP.png');
background-size: 100%;
background-repeat: no-repeat;
display: block;
width: 85%;
height: 85%;
content:"";
position: absolute;
top: 20%;
left: 10%;
}
How can I modify the CSS to that the image is under the thin blue border while being on top of the white.
Is that possible?
added z-index: -1000; for under.
ps: nice effect for scrollbar )
body {
background: #0d8aa5;
}
.loading {
position: absolute;
left: 50%;
top: 25%;
/*margin: -60px 0 0 -60px;*/
background: transparent;
width: 200px;
height: 200px;
border-radius: 100%;
border: 10px solid #19bee1;
}
.loading:after {
content: '';
background: trasparent;
width: 140%;
height: 140%;
position: absolute;
border-radius: 100%;
top: -20%;
left: -20%;
opacity: 0.7;
box-shadow: rgba(255, 255, 255, 0.6) -4px -5px 3px -3px;
animation: rotate 2s infinite linear;
}
#keyframes rotate {
0% {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(360deg);
}
}
.loading:before {
background-image: url('http://i.stack.imgur.com/UTnLP.png');
background-size: cover;
background-repeat: no-repeat;
display: block;
width: 100%;
height: 100%;
content: "";
position: absolute;
border-radius: 50%;
z-index: -1000;
}
<div class="loading"></div>
.loading {overflow: hidden} - just add this line
It is Because You are adding Background image before div.loading that makes images as content.Instead add background image to div.
HTML
<div class="container-screenz service-graphic sg2">
<div class="screenz monitor">
<img src="img/geoqueri-monitor.jpg">
</div>
<div class="laptop">
<div class="screenz">
<img src="img/geoqueri-laptop.jpg">
</div>
<div class="btm"></div>
</div>
<div class="phone">
<div class="screenz">
<img src="img/geoqueri-phone.jpg">
</div>
<div class="shadow"></div>
</div>
<div class="ipad">
<div class="screenz">
<img src="img/geoqueri-tablet.jpg">
</div>
</div>
</div>
CSS (with added prefixes)
#keyframes scroll {
20%,
60% {
-webkit-transform:translateY(-62%);
-moz-transform:translateY(-62%);
-ms-transform:translateY(-62%);
-o-transform:translateY(-62%);
transform:translateY(-62%);
}
80% {
margin-top: -50px;
}
}
.service-graphic {
max-width: 42.500em;
font-size: 8px;
padding: 1em;
position: relative;
display: block;
margin: 0 auto;
.monitor {
width: 28.750em;
height: 17.5em;
position: relative;
background: #f8f8f8;
border: 0.625em solid #1f1f1f;
#include border-radius(0.625em);
border: 1.25em solid #1f1f1f;
margin: 0 auto;
.content-screenz {
width: 26.25em;
height: 15em;
left: 50%;
margin-left: -13.125em;
overflow: hidden;
}
&:before, &:after {
content: "";
position: absolute;
left: 50%;
}
&:before {
top: -0.25em;
margin: -0.188em 0 0 -0.188em;
width: 0.250em;
height: 0.250em;
#include border-radius(0.250em);
background: #d8dbe1;
top: -0.625em;
}
}
.laptop {
&:before {
content: "";
position: absolute;
left: 50%;
top: -0.25em;
margin: -0.188em 0 0 -0.188em;
width: 0.250em;
height: 0.250em;
#include border-radius(0.250em);
background: #d8dbe1;
top: -0.625em;
}
}
}
.screenz {
&:after {
width: 0.500em;
height: 0.500em;
#include border-radius(0.500em);
margin: 0 0 -0.25em -0.25em;
background: #e8ebf0;
bottom: -0.625em;
}
}
.monitor > div {
position: absolute;
}
.monitor .content-screenz:before,
.laptop .screenz:before,
.phone .screenz:before,
.ipad .screenz:before {
content: "";
position: absolute;
right: -5.625em;
width: 12.500em;
height: 18.750em;
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
-ms-transform:rotate(45deg);
-o-transform:rotate(45deg);
transform:rotate(45deg);
/*linear-gradient*/
background:-webkit-gradient(linear,left top,left bottom,color-stop(rgba(255, 255, 255, 0.5),0),color-stop(rgba(255, 255, 255, 0),1));
/*##prefixmycss->No equivalent*/
background:-webkit-linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 100%);
background: -moz-linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 100%);
background: -o-linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 100%);
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 100%);
z-index: 5;
}
.browser {
width: 15em;
height: 11.250em;
position: absolute;
left: 50%;
top: 50%;
margin: -5.625em 0 0 -7.5em;
background: #ffffff;
border: 1px solid #e8ebf0;
border-top: 1.25em solid #d8dbe1;
#include border-radius(0.313em);
}
.browser-content {
overflow: hidden;
height: 9.938em;
padding-top: 0.625em;
}
.btns {
position: absolute;
top: -1.25em;
left: 0.438em;
&:before {
content: "";
position: absolute;
left: 2.188em;
top: 0.313em;
height: 0.625em;
width: 11.563em;
background: #fff;
#include border-radius(3px);
}
}
.btns > li {
display: inline-block;
list-style: none;
width: 0.313em;
height: 0.313em;
#include border-radius(0.313em);
background: #fc5254;
margin-right: 0.250em;
}
.btns li:nth-child(2) {
background: #fcae52;
}
.btns li:nth-child(3) {
background: #66b34e;
}
.base {
width: 5.625em;
height: 3.1em;
bottom: -3.9em;
left: 50%;
margin-left: -2.8125em;
background: #e8ebf0;
bottom: -4.3em;
z-index: -1;
}
.base:before,
.base:after,
.grey-shadow:before,
.grey-shadow:after {
content: "";
position: absolute;
top: 0;
}
.base:before {
border-left: 0.813em solid transparent;
border-right: 0px solid transparent;
border-bottom: 3.125em solid #e8ebf0;
left: -0.77em;
}
.base:after {
border-right: 0.813em solid transparent;
border-left: 0px solid transparent;
border-bottom: 3.125em solid #e8ebf0;
right: -0.77em;
}
.base > div {
position: absolute;
}
.grey-shadow {
width: 5.625em;
height: 0.750em;
background: #d8dbe1;
top: 0;
}
.grey-shadow:before {
border-left: 3px solid transparent;
border-right: 0px solid transparent;
border-bottom: 0.75em solid #d8dbe1;
left: -3px;
}
.grey-shadow:after {
border-right: 3px solid transparent;
border-left: 0px solid transparent;
border-bottom: 0.75em solid #d8dbe1;
right: -2px;
z-index: 1;
}
.foot {
background: #e8ebf0;
}
.foot.top {
width: 7.250em;
height: 0.313em;
bottom: -0.3em;
left: 50%;
margin-left: -3.625em;
}
.foot.top:before,
.foot.top:after,
.foot.bottom:before {
content: "";
position: absolute;
top: 0px;
}
.foot.top:before {
border-left: 16px solid transparent;
border-right: 0px solid transparent;
border-bottom: 5px solid #e8ebf0;
left: -16px;
}
.foot.top:after {
border-right: 1em solid transparent;
border-left: 0px solid transparent;
border-bottom: 5px solid #e8ebf0;
right: -1em;
}
.foot.bottom {
width: 9.375em;
height: 0.313em;
bottom: -0.625em;
left: 50%;
margin-left: -4.688em;
}
.laptop {
width: 14.688em;
height: 9.688em;
background: #f8f8f8;
border: 0.75em solid #1f1f1f;
-webkit-border-radius:10px 10px 0 0;
-moz-border-radius:10px 10px 0 0;
border-radius:10px 10px 0 0;
position: absolute;
top: 14.5em;
right: 1.875em;
z-index: 10;
}
.laptop:before {
top: -0.3em;
}
.laptop > div {
position: absolute;
}
.laptop > .screenz {
width: 13.188em;
height: 8.188em;
left: 0;
margin-left: 0;
background: #fff;
overflow: hidden;
}
.btm {
width: 18.500em;
height: 0.625em;
bottom: -1.188em;
left: 50%;
margin-left: -9.25em;
-webkit-border-radius:0 0 20px 20px;
-moz-border-radius:0 0 20px 20px;
border-radius:0 0 20px 20px;
background: #e8ebf0;
z-index: 1;
}
.btm:before {
content: "";
position: absolute;
width: 42px;
height: 4px;
left: 50%;
top: 0;
margin-left: -21px;
-webkit-border-radius:0 0 5px 5px;
-moz-border-radius:0 0 5px 5px;
border-radius:0 0 5px 5px;
background: #d8dbe1;
}
.btm:after {
display: none;
content: "";
position: absolute;
width: 100%;
height: 0.25rem;
background: #bababa;
top: .5rem;
border-bottom-right-radius: 7.5rem 2.5rem;
border-bottom-left-radius: 7.5rem 2.5rem;
}
.phone {
width: 4.125em;
height: 8.750em;
position: absolute;
top: 15.75em;
left: 1em;
#include border-radius(0.5em);
background: #1f1f1f;
border: 1.563em solid #1f1f1f;
border-left: 0.313em solid #1f1f1f;
border-right: 0.313em solid #1f1f1f;
}
.phone:before,
.phone:after {
content: "";
position: absolute;
left: 50%;
background: #474e5d;
}
.phone:before {
background: #474e5d;
width: 1.250em;
height: 0.250em;
margin-left: -0.625em;
top: -0.75em;
#include border-radius(2px);
}
.phone:after {
width: 0.625em;
height: 0.625em;
#include border-radius(0.625em);
bottom: -1.125em;
margin-left: -0.313em;
}
.phone .screenz {
width: 3.50em;
height: 5.625em;
margin: 0 auto;
position: relative;
overflow: hidden;
background: #fff;
}
.ipad {
width: 8.75em;
height: 12.750em;
position: absolute;
top: 11.7em;
left: 6em;
#include border-radius(0.5em);
background: #1f1f1f;
border: 1.563em solid #1f1f1f;
border-left: 0.313em solid #1f1f1f;
border-right: 0.313em solid #1f1f1f;
}
.ipad:before,
.ipad:after {
content: "";
position: absolute;
left: 50%;
background: #474e5d;
}
.ipad:before {
background: #474e5d;
width: 1.250em;
height: 0.250em;
margin-left: -0.625em;
top: -0.75em;
#include border-radius(2px);
}
.ipad:after {
width: 0.625em;
height: 0.625em;
#include border-radius(0.625em);
bottom: -1.125em;
margin-left: -0.313em;
}
.ipad .screenz {
width: 8em;
height: 9.8em;
margin: 0 auto;
position: relative;
overflow: hidden;
background: #fff;
}
.ipad .content {
width: 100%;
left: 0%;
margin-left: 0px;
}
.monitor , .laptop, .ipad, .phone {
overflow: hidden;
img {
padding: 0 !important;
width: 100%;
height: 880px;
-webkit-animation:scroll 4s 1s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
-moz-animation:scroll 4s 1s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
-ms-animation:scroll 4s 1s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
-o-animation:scroll 4s 1s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
animation:scroll 4s 1s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
&:hover {
opacity: 1 !important;
}
}
}
#media screen and (min-width: 38em) {
.service-graphic {
font-size: 12px;
.monitor {
border: 1.25em solid #1f1f1f;
}
}
}
Original unmodified codepen :
http://codepen.io/nicholaspetersen/pen/BHjfk
So what I did was, I converted the LESS to CSS (since I do not know LESS) using
http://less2css.org/
The animation worked perfectly for Firefox, however on Chrome it did not. So I went through the code and added all the missing prefixes, as you can see in the CSS code I provided and it still does not work. I am now clueless, why will this work on Firefox but not Chrome?
Thanks
It's not enough to just add the prefixed transformations inside of a keyframe animation, you need to prefix the keyframe declaration itself as well. For example:
#-webkit-keyframes foo {
0% {
-webkit-transform: scale(0);
}
100% {
-webkit-transform: scale(1);
}
}
Also worth noting, you can view the compiled LESS in codepen by clicking on the 'eye' icon in the CSS pane. Hope this helps bud