1

I have done s simple heart using pure CSS. It consists of two pieces, so one piece has a white box-shadow, the other one has a red one.

An example can be found here: JsFiddle (it has a simplified styling with no gradients, so it may not look beautiful :)

So, the question is: how to create animated shadows? All I need is to make white and red shadows pulsating to create an effect of heartbeat.

I have followed through some similar questions already, but they won't work, unfortunately, just because in my case I use :after and :before pseudo-classes, which can not been manipulated via jQuery.

Max Krizh
  • 585
  • 3
  • 7
  • 34

1 Answers1

5

I set it to infinite so it beats non-stop (which is a good thing, so the heart doesn't die right?) But you can change it to n number of times instead. Also, you can change the 5 seconds to longer or shorter obviously. And if you don't want the box shadow going to 0, you can always change that to like 10px or something too.

#b:before {
    animation: heartbeat 5s infinite;
}

@keyframes heartbeat {
    0% { box-shadow: 0 0 50px #fff; }
    25% { box-shadow: 0 0 0 #fff; }
    50% { box-shadow: 0 0 50px #fff; }
    75% { box-shadow: 0 0 0 #fff; }
    100% { box-shadow: 0 0 50px #fff; }
}

body {
    width:100%;
    margin:0;
    background: #000;
}
#b {
    position:relative;
    width:500px;
    height:90px;
    margin: 100px auto;
    font-size: 12px;
}
#b:before {
    position: absolute;
    content:"";
    left: 208px;
    top: 10px;
    width: 208px;
    height: 320px;
    background: red;
    border-radius: 200px 200px 0 0;
    box-shadow: 0 0 50px #fff;
    animation: heartbeat 5s infinite;
}
#b:before {
    -webkit-transform: rotate(-45deg);
    -moz-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    -o-transform: rotate(-45deg);
    transform: rotate(-45deg);
    -webkit-transform-origin: 0 100%;
    -moz-transform-origin: 0 100%;
    -ms-transform-origin: 0 100%;
    -o-transform-origin: 0 100%;
    transform-origin: 0 100%;
}
#b:after {
    position:absolute;
    content:"BlaBla!";
    color: #fff;
    left:0;
    top:10px;
    width:208px;
    height:320px;
    background: red;
    border-radius:200px 200px 0 0;
    -webkit-transform:rotate(45deg);
    -moz-transform:rotate(45deg);
    -ms-transform:rotate(45deg);
    -o-transform:rotate(45deg);
    transform:rotate(45deg);
    -webkit-transform-origin:100% 100%;
    -moz-transform-origin:100% 100%;
    -ms-transform-origin:100% 100%;
    -o-transform-origin:100% 100%;
    transform-origin:100% 100%;
    box-shadow: 10px 10px 100px #6d0019;
}

@keyframes heartbeat {
    0% { box-shadow: 0 0 50px #fff; }
    25% { box-shadow: 0 0 0 #fff; }
    50% { box-shadow: 0 0 50px #fff; }
    75% { box-shadow: 0 0 0 #fff; }
    100% { box-shadow: 0 0 50px #fff; }
}
<div class="a">
    <div id="b"></div>
</div>
CRABOLO
  • 8,605
  • 39
  • 41
  • 68
  • hi, it looks so cool, only one thing left. There is no glowing on the right top corner. Why? and How to fix it? – Franva Mar 29 '15 at 09:53