Card Reveal Effect || card reveal animation, card hover effect

 Card Reveal Animation

If you want to reveal a card of your webpage in a way that looks cool then this post is for you. Watch the tutorial video or copy the source code and use in your project.




Source Code

1. HTML

<div id="base">
  <p>click/tap on numbers</p>
  <div class="card one">
    <span>1</span>
    <h1>card one</h1>
    <p>🤩</p>
  </div>
  <div class="card two">
    <span>2</span>
    <h1>card two</h1>
    <p>🤗</p>
  </div>
  <div class="card three">
    <span>3</span>
    <h1>card three</h1>
    <p>😍</p>
  </div>
</div>

The code creates a div element with the id base. This is the main container for the other elements in the code. The next element is a p element with the text "click/tap on numbers". This is a simple instruction for the user.

The next three elements are all div elements with the class card. These elements represent the three cards that the user can click on. Each card has a number, a heading, and an emoji.

The code uses the id attribute to give the main div element a unique identifier. This identifier can be used to access the element in JavaScript. The class attribute is used to give the three div elements with the class card a common style.

The code also uses the span element to display the numbers 1, 2, and 3. The h1 element is used to display the headings "card one", "card two", and "card three". The p element is used to display the emojis 🤩, 🤗, and 😍.

2. CSS

STEP-1

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: monospace;
}

The code *{ margin: 0; padding: 0; box-sizing: border-box; font-family: monospace; } is a CSS reset rule. It sets the margin, padding, and box-sizing properties of all elements to 0, and the font-family property to monospace.

In this case, the CSS reset rule ensures that all elements have no margin, padding, or border, and that they use the monospace font family. This can be useful for ensuring that all elements on a page have a consistent look and feel.


STEP-2

#base{
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

The height: 100vh property sets the height of the element to 100% of the viewport height.

The display: flex property tells the browser to display the element as a flex container.

The align-items: center property aligns the child elements of the flex container vertically in the center.

The justify-content: center property aligns the child elements of the flex container horizontally in the center.


STEP-3

.card{
  color: white;
  position: absolute;
  height: 250px;
  width: 200px;
  border-radius: 15px;
  transition: all ease-in-out 0.5s;
}

The color property sets the color of the card to white.

The position property sets the position of the card to absolute. This means that the card will be positioned relative to its parent element.

The height and width properties set the height and width of the card to 250px and 200px respectively.

The border-radius property sets the border radius of the card to 15px. This will give the card a rounded corners.

The transition property sets the transition for the card. This means that the card will animate when it is moved or resized. The transition will last for 0.5 seconds and the animation will use the ease-in-out easing function.


STEP-4

span{
position: absolute;
font-size: 1.2em;
color: white;
display: inline-block;
height: 32px;
width: 32px;
padding-left: 12px;
padding-top: 6px;
}

Position: The position property specifies the position of the element on the page. In this case, the position property is set to absolute, which means that the element will be positioned relative to its parent element.

Font size: The font-size property specifies the size of the text in the element. In this case, the font-size property is set to 1.2em, which means that the text will be 1.2 times the size of the default text size.

Color: The color property specifies the color of the text in the element. In this case, the color property is set to white, which means that the text will be white.

Display: The display property specifies how the element is displayed on the page. In this case, the display property is set to inline-block, which means that the element will be displayed as an inline block element.

Height: The height property specifies the height of the element. In this case, the height property is set to 32px, which means that the element will be 32 pixels tall.

Width: The width property specifies the width of the element. In this case, the width property is set to 32px, which means that the element will be 32 pixels wide.

Padding: The padding property specifies the amount of padding around the element. In this case, the padding property is set to 12px 6px, which means that there will be 12 pixels of padding on the left and 6 pixels of padding on the top.


STEP-5

.two > span{
  left: calc(50% - 16px);
}
.three > span{
  left: calc(100% - 32px);
}

The code is using CSS to position two spans, one with the class name .two and the other with the class name .three. The left property of each span is being set to a calculated value using the calc() function. The calc() function allows you to calculate a value based on other values in the CSS code.

In this case, the left property of the .two span is being set to calc(50% - 16px). This means that the span will be positioned 16 pixels to the left of the center of its container. The left property of the .three span is being set to calc(100% - 32px). This means that the span will be positioned 32 pixels to the right of the edge of its container.

So, in short, the code is positioning two spans, one 16 pixels to the left of the center of its container and the other 32 pixels to the right of the edge of its container.


STEP-6

.card > p{
  font-size: 2em;
  position: relative;
  top: 40%;
  text-align: center;
}

The code tells the browser to:

Set the font size of the paragraph to 2em.

Position the paragraph relative to the card element, and place it 40% from the top of the card.

Align the text of the paragraph to the center of the card.


Here is a breakdown of the code:

.card > p - This selector tells the browser to style the paragraph element that is inside of the card element.

font-size: 2em - This property sets the font size of the paragraph to 2em. An em is a unit of measurement that is equal to the current font size. So, 2em means that the font size will be twice the current font size.

position: relative - This property tells the browser to position the paragraph relative to its parent element, in this case the card element.

top: 40% - This property sets the top position of the paragraph to 40% of the height of the card element.

text-align: center - This property aligns the text of the paragraph to the center of the card element.


STEP-7

.card > h1{
  font-size: 1.5em;
  position: relative;
  top: 30%;
  text-align: center;
}

The .card > h1 selector selects all h1 elements that are children of a .card element.

The font-size: 1.5em property sets the font size of the h1 element to 1.5 times the default size.

The position: relative property makes the h1 element position relative to its parent element.

The top: 30% property positions the h1 element 30% from the top of its parent element.

The text-align: center property centers the text of the h1 element.

In short, this code will make all h1 elements that are children of a .card element 1.5 times larger, position them 30% from the top of their parent element, and center the text.


STEP-8

.one{
  background-color: peru;
  clip-path: circle(16px at 16px 16px);
  z-index: 3;
}

The .one selector is used to select an element with the class name one.

The background-color property sets the background color of the element to peru, which is a dark orange color.

The clip-path property defines a clipping region for the element. In this case, the clipping region is a circle with a radius of 16 pixels, and its center is located at the coordinates (16, 16). This means that only the part of the element that falls within the circle will be visible.

The z-index property sets the z-index of the element. The z-index determines the stacking order of elements, with elements with a higher z-index being displayed on top of elements with a lower z-index. In this case, the z-index of the element is set to 3, which means that it will be displayed on top of elements with a z-index of 1 or 2.

In other words, this code will create an element with a dark orange background color and a circular clipping region. The element will be displayed on top of elements with a z-index of 1 or 2.


STEP-9

.two{
  background-color: teal;
  clip-path: circle(16px at 50% 16px);
  z-index: 2;
}

The background-color property sets the background color of the element. In this case, the background color is teal.

The clip-path property defines a clipping region for the element. The clipping region is a circle with a radius of 16px. This means that only the part of the element that is inside the circle will be visible.

The z-index property specifies the stacking order of the element. In this case, the element has a z-index of 2. This means that the element will be displayed on top of elements with a z-index of 1 or less.


Here is a short summary of the code:

The element with the class name two will have a teal background color.

The element will be clipped to a circle with a radius of 16px.

The element will be displayed on top of elements with a z-index of 1 or less


STEP-10

.three{
  background-color: blueviolet;
  clip-path: circle(16px at calc(100% - 16px) 16px);
  z-index: 1;
}

The background-color property is a CSS property that sets the background color of an element. The value of the property can be any valid CSS color value, such as blueviolet.

The clip-path property is a CSS property that defines a clipping region for an element. The clipping region is a shape that determines which parts of the element are visible and which parts are hidden. The value of the clip-path property can be a circle, an ellipse, a polygon, or a path.

The z-index property is a CSS property that sets the stacking order of an element. The stacking order determines which elements are displayed on top of other elements. The higher the z-index of an element, the higher it will be displayed in the stack.


STEP-11

.one:hover{
  background-color: peru;
  clip-path: circle(70%);
}

.one:hover - This is the selector that targets the element with the class name one. The :hover part of the selector indicates that the style will be applied when the element is hovered over.

background-color: peru - This sets the background color of the element to peru, which is a dark brown color.

clip-path: circle(70%) - This clips the element to a circle with a radius of 70% of the element's width. This means that only the part of the element that is inside the circle will be visible.


STEP-12

.two:hover{
  background-color: teal;
  clip-path: circle(70%);
}

.two:hover is the selector. It tells the browser to apply the following styles to any element with the class name two when the mouse is hovered over it.

background-color: teal is the first style. It sets the background color of the element to teal.

clip-path: circle(70%) is the second style. It clips the element to a circle with a radius of 70%.


STEP-13

.three:hover{
  background-color: blueviolet;
  clip-path: circle(70%);
}

.three:hover is the selector. It tells the browser that this code applies to any element with the class name .three when it is hovered.

background-color: blueviolet sets the background color of the element to blueviolet when it is hovered.

clip-path: circle(70%) clips the element to a circle that is 70% of the element's width and height when it is hovered.


STEP-14

.one:hover ~ .two, .one:hover ~ .three{
  z-index: 3;
}

The z-index property determines the stacking order of elements on a page. A higher z-index value means that an element will be stacked on top of elements with lower z-index values.

In this case, the .one:hover ~ .two and .one:hover ~ .three selectors mean that the .two and .three elements will be stacked on top of all other elements on the page when the .one element is hovered over.


STEP-15

.two:hover ~ .three{
  z-index: 3;
}

.two:hover ~ .three - This selector specifies that the code should only be applied to the .three element when the .two element is hovered over.

z-index: 3 - This property specifies the z-index of the .three element when it is hovered over. A higher z-index value means that the element will appear on top of elements with lower z-index values.

In short, this code will cause the .three element to appear on top of the .two element when the user hovers over the .two element.


---END---

Comments