Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Vinod Godti
Vinod Godti

Posted on

     

CSS Shapes with Animation

You can do wonders with simple CSS properties in the designing world.for example you can create a simple arrow symbol or heart with beating. So let's learn how to create different shapes in CSS and add animation property to shapes that are created.

Circle

To create a circle, we have to first create div element and assign width and height CSS property. Add some background color and make border-radius 50%.

.circle{   width:100x;   height:100px;   background:#159AC1;   border-radius:50%; }
Enter fullscreen modeExit fullscreen mode

Rectangle

To create a rectangle, We have to create a div element and assign width and height CSS property. Add some background color to make more clearly visible.

.rectangle{   width:100x;   height:50px;   background:#159AC1;}
Enter fullscreen modeExit fullscreen mode

Triangle

To create a triangle shape, we have to user border property as with position: absolute. See the CSS code below.

.triangle-up{    position: absolute;    border-right: 20px solid transparent;    border-left: 20px solid transparent;    border-bottom: 20px solid tomato;}.triangle-down{    position: absolute;    border-top:20px solid tomato;    border-left:20px solid transparent;    border-right:20px solid transparent;}.triangle-right{    position:absolute;    border-right:20px solid tomato;    border-top:20px solid transparent;    border-bottom:20px solid transparent;}.triangle-left{    position: absolute;    border-left: 20px solid tomato;    border-top: 20px solid transparent;    border-bottom: 20px solid transparent;}
Enter fullscreen modeExit fullscreen mode

Quarter Moon

To create the quarter moon, First, create circle white background and apply box-shadow

.quarter-moon {    position: relative;    width: 50px;    height: 50px;    border-radius: 50%;    background: #fff;    box-shadow: 10px 10px 0 0 pink;}
Enter fullscreen modeExit fullscreen mode

Heart

To create a heart shape, We should use pseudo-class before and after. We used scale rotate & scale transform properties in animation keyframe to show heartbeat

.heart{        position: relative;    }.heart:before {    content: "";    position: absolute;    width: 50px;    height: 75px;    left: 0px;    border-radius: 50px 50px 0 0;    background: pink;    transform: rotate(-45deg);    animation: heart-pump 1s infinite;}.heart:after {    content: "";    position: absolute;    width: 50px;    height: 75px;    left: 20px;    border-radius: 50px 50px 0 0;    background: pink;    transform: rotate(45deg);    animation: heart-pump-1 1s infinite;}
Enter fullscreen modeExit fullscreen mode

Adding heart-beat animation

@keyframes heart-pump {    to {        transform: rotate(-45deg) scale(1.2);    }}@keyframes heart-pump-1 {    to {        transform: rotate(45deg) scale(1.2);    }}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am coding geek ,interest learning new technologies in web and mobile app development.My technology stack is JavaScript | React | React Native | Node/Express | Mysql/MongoDb.
  • Location
    Bengaluru,India
  • Education
    Bachelor Degree in Computer Science
  • Work
    Full Stack Javascript Developer at Octopolis Technologies
  • Joined

More fromVinod Godti

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp