Simple CSS Border Animation with before and after Selector

In this tutorial we will see how to create Simple CSS Border Animation with before and after Selector. CSS ::before and ::after pseudo elements or selectors are used to create this rotating border animation effect.

HTML Code

HTML Code is given below, in this code we have a main div with class = 'card'.

<div class="card">
</div>    

CSS Code

CSS Code is given below, ::before selector is to create border for the main card div, while ::after selector is used to create the overlay. CSS transform property is used to rotate the border element of the card. This creates the border rotation animation effect.

body
{
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: #333;
    font-family: 'Barlow Condensed' , sans-serif;
}
.card
{
    width: 200px;
    height: 250px;
    background-color: #000;
    position: relative;
    box-shadow: 0px 0px 5px 2px #000;
    cursor: pointer;
    overflow: hidden;
}
.card::before
{
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%) rotate(-280deg);
    width: 160%;
    height: 130%;
    background-image: conic-gradient(#ff00bb 0deg, #ff00bb 90deg, transparent 130deg, transparent 180deg, #4530FF 180deg, #4530FF 270deg, transparent 310deg, transparent 360deg);
    transition: transform 2s;
}
.card:hover::before
{
    transform: translate(-50%,-50%) rotate(-100deg);
}
.card::after
{
    content: 'HowToCodeSchool.com';
    color: #ddd;
    position: absolute;
    background-color: #000;
    display: flex;
    font-size: 17px;
    align-items: center;
    justify-content: center;
    height: 242px;
    width: 192px;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
}

Demo

Video Tutorial

Watch our video tutorial on Simple CSS Border Animation with before and after Selector.

Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Simple Price Range Slider With HTML CSS and JavaScript Circle With Two Colors using CSS Card With Ribbon using HTML and CSS Simple Loading Screen using HTML and CSS Disable Textarea Resizable Property using CSS Button like Links using CSS Simple Dropdown Menu Using HTML and CSS Background Color Transition using CSS Highlight Required Input Fields using CSS Disable HTML Link using CSS Difference Between Descendant Selector and Child Selector How To Change Color and Size of Hr Tag Using CSS How To Center Align HTML Table Convert Checkbox To Toggle Button Using CSS Drawing Stars using HTML and CSS Button Bounce Effect using CSS Image as Text Background using CSS background-clip Property Vertically Rotate HTML Element using CSS Vertical Align Middle using CSS Text Over Image Hover Effect - Css Hover Simple CSS Button Hover Effect using Before Selector