Animating elements with folding effects using CSS transforms

Check out this square: https://jsfiddle.net/34f93mL3/

If you hover over it, you'll see that the top folds down and turns into a pink polka-dotted pattern when it reaches the bottom.

However, my goal is to make it look more like an actual folding motion, where the polka dots appear only after it's "folded" a little further.

Below is the complete code using only HTML and CSS:

body {
  background: white
}
#slow-container {
  top: 100px;
  left: 200px;
  height: 50px;
  position: absolute;
  width: 100px;
  background: lightblue;
}
#slow-container:before {
  top: -50px;
  height: 50px;
  position: absolute;
  width: 100px;
  background: lightblue;
}
#slow-container2 {
  top: -50px;
  height: 50px;
  position: absolute;
  width: 100px;
  background: lightblue;
}
.slow-parent1 {
  height: 0;
  overflow: hidden;
  background: lightgreen;
}
.slow-parent2 {
  background: white;
}
.slow-parent3 {
  height: 300px;
  background: red;
}
#slow-container2 {
  transition: all 1s linear;
  transform-origin: bottom center;
}
#slow-container:hover #slow-container2 {
  transform: rotateX(180deg);
  background-color: lightpink;
  background-image: radial-gradient(#fff 10%, transparent 10%), radial-gradient(#fff 10%, transparent 10%);
  background-size: 30px 30px;
  background-position: 0 0, 15px 15px;
}
<div id="slow-container">
  <div id="slow-container2">
  </div>
  <div class="slow-parent1">
    <div class="slow-parent2">
      <div class="slow-parent3">
        stuff goes here later
      </div>
    </div>
  </div>
</div>
</div>

Answer №1

To enhance your hover effect, simply delete #fff 10%, from the radial gradient in your code.

Answer №2

Implement the folding effect using CSS3 properties like perspective.

For more information, check out: https://css-tricks.com/almanac/properties/p/perspective/

body {
  background: white
}
#slow-container {
  top: 100px;
  left: 200px;
  height: 50px;
  position: absolute;
  width: 100px;
  background: lightblue;
}
#slow-container:before {
  top: -50px;
  height: 50px;
  position: absolute;
  width: 100px;
  background: lightblue;
}
#slow-container2 {
  top: -50px;
  height: 50px;
  position: absolute;
  width: 100px;
  background: lightblue;
}
.slow-parent1 {
  height: 0;
  overflow: hidden;
  background: lightgreen;
}
.slow-parent2 {
  background: white;
}
.slow-parent3 {
  height: 300px;
  background: red;
}
#slow-container2 {
  transition: all 1s linear;
  transform-origin: bottom center;
}
#slow-container:hover #slow-container2 {
  transform: perspective(200px) rotateX(180deg);
  background-color: lightpink;
  background-image: radial-gradient(#fff 10%, transparent 10%), radial-gradient(#fff 10%, transparent 10%);
  background-size: 30px 30px;
  background-position: 0 0, 15px 15px;
}
<div id="slow-container">
  <div id="slow-container2">
  </div>
  <div class="slow-parent1">
    <div class="slow-parent2">
      <div class="slow-parent3">
        stuff goes here later
      </div>
    </div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to address the excess white space between an image and progress bar on larger screens while utilizing the Bootstrap Grid system?

https://i.sstatic.net/NXMNV.pngLet's begin by visualizing the concept through these images: In Picture (1), the progress bars are positioned below the image on medium to large screens, with the text aligned to its right. https://i.sstatic.net/Cw1aM.pn ...

Showcasing images that vary between mobile and desktop views using Bootstrap 4

I have a website where I display 6 columns of images in a row using Bootstrap 4. However, I want to adjust the layout so that when viewed on mobile devices with a smaller screen width, the images are displayed in rows of 4 or 3 columns instead. <link ...

CSS Issue: When nesting divs, text moves to the top of the second page

Currently, I am using the following HTML and inline CSS: <div style="width: 975px; clear: both; float: left; text-align: left; margin: 0; background-color: #D3D3D3;"> <div style="width: 384px; float: left; height: 20px; margin: 0;"> ...

Changing the background color of a fixed header in AngularJS based on the current page

I designed my homepage with a full-height div featuring a video. The header is fixed in position and has a transparent background with white text when positioned over the video. As I scroll down, I dynamically adjust the background to white with black text ...

Once I press the button to switch all the other buttons to dark mode, it only successfully changes them once

I created a button that switches the entire page to dark mode. I also have some dark buttons that I want to switch to light when the dark mode button is clicked. The issue is that while changing the page to dark mode works, the dark buttons only toggle ...

Tips on sending a form to the server with ajax technology

I'm struggling with sending a button id to my server through ajax in order to submit a form without having to constantly reload the page every time I click on a button. Unfortunately, it's not working as expected and I can't figure out why. ...

Empty gaps separating two divs nested within another div within a div (unable to function)

I'm diving into the world of HTML, CSS, and JS as I embark on creating a weather application. My vision is to include the temperature, followed by the city and its corresponding weather (accompanied by an icon), and lastly additional details like humi ...

Ways to conceal and reveal content within div elements

I have a code snippet that is currently operational, but I am looking to enhance it by displaying one div at a time. If you would like to view the code, please visit my CodePen link below: https://codepen.io/danongu/pen/YzXvpoJ Due to the extensive amou ...

Mobile responsiveness issue with basic bootstrap navigation bar not collapsing

After trying everything possible, I am still unable to resolve my issue and it is leaving me puzzled. MY ISSUE Simplifying my page, I used the example from w3schools for a responsive navbar. When resizing the browser window, the navbar collapses correctl ...

My table elements are automatically being populated with <tr> elements thanks to Javascript

Upon viewing the screenshot: https://i.sstatic.net/Pwv2v.png it is evident that each element is placed within its own tr. My preference is to have each element contained in a td and then wrap everything within a single tr. Here is the updated HTML stru ...

What is the reason for Javascript's inability to apply height using the ex unit measurement?

Is there a way to use JavaScript in order to increase the height of an element based on its current CSS height value? I've been able to do it using px units, but not with ex units. Can anyone provide a solution for this? Here is the HTML structure: ...

Is there a way to retrieve and update the data of all the child elements within a table row dynamically?

I have a table with the following header information. <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th> Date ...

What could be preventing the background image from displaying properly?

I had the idea to create a game where players have to flip cards to reveal what's on the back, but I'm struggling to get the background image to display properly. As a newcomer to Vue, I'm not sure if I made a mistake somewhere. My intuition ...

Modifying input values in AngularJS/HTML

I'm encountering an issue with the ng-repeat function in AngularJS within my HTML code. The problem is that when I change the input with the ID 'add-price' in one cartproduct, it simultaneously changes in all other cartproducts as well. For ...

It is not possible for me to restore a previously deleted element from the table

<table class="files-table table"> <thead> <th>Filename</th> <th>Type</th> <th>Status</th> <th oncli ...

What methods are available to test my website across different browsers such as outdated versions of Internet Explorer like IE8?

Currently, I am working on Chrome with Windows 7 OS installed. However, Windows 7 does not support Internet Explorer 8. This is causing issues when trying to view my web pages in the IE8 version and older. How can I resolve this problem? I have attempted ...

Steps to ensure a div spans the entire height of the browser window

In the design of my webpage, I have organized content into two columns - a left div and a right div. The right div is styled with a grey background-color, and I am looking to make it expand vertically based on the user's browser window height. Curren ...

I'm curious about something I noticed in an HTML example within the text content section of elements. Can you help clarify this for me?

I recently came across a repository that was part of a bootcamp curriculum for learning full stack development. In one of the lessons on jQuery, students were tasked with building a calculator. However, I noticed some strange variables in the HTML where te ...

Is it possible to create a single CSS style class that can be used for various section tiles on a website?

I am currently working on a website that includes different section titles such as About, Projects, Contact, and more. To make these titles stand out against the background image, I have decided to fill them with white. The text color of the titles is dar ...

Troubleshooting varying <li> heights in Google Chrome with CSS

Kindly review the image enclosed below ul li{ width:100px; height:200px; float:left; border:10px double #333; -webkit-border-radius: 10px; -moz-border-radius: 10px; } <ul> <li><a href="image.jpg"><img src ...