Creating dynamic paper curl effect using CSS for mobile responsiveness

Looking to achieve the curl and shadow effect like the one on w3resource's code box? Take a peek at the example here:
This effect is responsive, with the sides showing the desired effect while the middle part shortens as the window narrows.
There are various examples of this effect online, but finding a truly responsive version can be challenging. w3resource uses inline styles for this, so it should be easily achievable by someone experienced in web development.

Answer №1

The concept of the curl effect is essentially a visual trickery. There isn't an actual curl present, as the 'paper' appears to be curling due to the play of shadows at the bottom of the element.

To achieve this effect, shadows are strategically applied using pseudo elements before and after the 'piece of paper'. By manipulating the sizing and positioning of these shadows, you can customize the illusion to suit your desired outcome, adjusting between percentage values, ems, or even pixels for different sizes of 'paper'.

Below is a basic code snippet to help you get started with creating the curl effect. The example provided is responsive, adapting to the size of the paper and shadow using percentage values. You may want to experiment further with using % for the shadow compared to ems or consider using vmin for maintaining the aspect ratio suitable for A4 or letter paper dimensions.

.curl {
  width: 60vmin;
  height: 80vmin;
  background-color: #eeeeee;
  position: relative;
  border: solid 0.5px #fefefe;
}
div.curl:after {
  right: 0.75em;
  left: auto;
  transform: rotate(2deg);
}
div.curl:before, .curl:after {
  content: '';
  z-index: -2;
  display: block;
  position: absolute;
  bottom: 0.75em;
  left: 0.18em;
  width: 40%;
  height: 20%;
  box-shadow: 0px 13px 8px #979797;
  transform: rotate(-2deg);
}
<div class="curl"></div>

Answer №2

Applying two box shadows is essential, starting with:


box-shadow: 0 2px 2px 0 rgb(0 0 0 / 14%),
 0 3px 1px -2px rgb(0 0 0 / 20%),
 0 1px 5px 0 rgb(0 0 0 / 12%);

The next shadow, in a different class, will be:

0 6px 10px 0 rgb(0 0 0 / 14%),
0 1px 18px 0 rgb(0 0 0 / 12%),
0 3px 5px -1px rgb(0 0 0 / 20%);

To ensure responsiveness, begin by setting the div's width: 100%;. For a complete page layout, consider using flexbox or grid.

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

Troublesome formatting problem with CSS for beginners

Just joined this platform and I'm excited to post my first question here. Hopefully, I've done it correctly. I'm currently following a YouTube course on DOM manipulation to create a Javascript stopwatch. You can find the course here. I&apo ...

Customize input field width in Bootstrap 4

Is it possible to adjust the width of the input field using the provided starter template? https://getbootstrap.com/docs/4.1/examples/starter-template/ I am specifically looking to reduce the size of this section: <form class="form-inline my-2 my-lg- ...

Ensure that the .md formatting is maintained when using a fresh CSS paragraph selector

I recently added a new selector in the .css file for my Hugo website to implement MLA-style indentation for references. Here is the code snippet: .mla-ref { padding-left: 36px; text-indent: -36px; } Although this code creates a hanging indent as ...

How come the text is not centered when I use text-align:center; on my class "text5"?

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Homepage</title> ...

Aligning the text vertically in the center while also rotating it 90 degrees to the right, alongside blocking the image and icon elements

I have been experimenting with Bootstrap Trying to create a layout with an image aligned to the top right, a rotated paragraph with a star symbol, and a vertical arrangement of five star symbols. Here's a screenshot of what I'm aiming for: Scre ...

Expanding and Shrinking Text Areas with Jquery

I am looking to create a textarea that comes preloaded with content. The height of the textarea should adjust to auto when there is content present, but switch to a height of 4.2rem when it is empty. Additionally, I want the textarea to dynamically increas ...

Looking to temporarily hide a transparent div while the page is loading, and then reveal it once the page has finished loading?

Hey, I've created a code for a transparent div that I'm using behind some text on the homepage of a website to make the text more prominent: #transdiv { position:absolute; top:228px; width:852px; height:160px; background-colo ...

When the value equals 25

I am seeking to implement a text field where users can input a number, and based on whether it's correct or not, display "image a" for the correct answer and "image b" for an incorrect one below the text field. I want users to have multiple attempts u ...

Adjusting the height of a Vue component to 100% triggers a change in height whenever a re-render occurs

In my Vue component, there is a class called "tab-body-wrapper" that serves the purpose of displaying the "slot" for the active tab. However, I encountered an issue while troubleshooting where the height of the ".tab-body-wrapper" component reduces during ...

Is it possible to apply a complete style sheet to a single div element only?

I'm currently working on a website and I want to incorporate a dynamic bootstrap calendar. The issue I'm facing is that my site has its own style sheet, but the calendar comes with its own styles. When I try to integrate the two, it seems like el ...

Struggled to Find a Solution for Code Alignment

Is there a tool or software that can align different types of codes with just one click? I've tried using the Code alignment plugin in Notepad++, but it hasn't been effective. For example, when aligning HTML code using tags, I couldn't find ...

Stylish tag colors in ExtJS 3 SuperBoxSelect

My SuperBoxSelect element is being populated from a remote store. I am looking to assign a different color to each tag when it is selected. The color value for each tag comes from the store. Currently, I am attempting to achieve this by using the followi ...

Display subpages of WordPress site in a dropdown menu on the navigation bar

Currently in the process of converting an HTML website to Wordpress, I am encountering a challenge. The issue lies in my attempt to add a drop-down feature to the navigation list using the wp_list_pages tag. As it stands, when hovering over the "products" ...

Can I apply a different color to every row in an HTML selector?

My question involves using an HTML selector that allows the user to choose a color. <select name="color" class="form-control"> <option value="ff0000">Red</option> <option value="ff7f00">Orange</option> <option value= ...

Gradient scroll effect for dynamic backgrounds

I am currently working on a code where I want the background to scroll instead of the text. This means that the text will stay fixed in its position while the background scrolls behind it on the page. Any suggestions on how I can achieve this? For an ex ...

adjusting three sections within a flexible navigation bar

Having difficulties creating a dynamic navbar that changes on scroll and keeping the elements within the nav fixed when the menu options appear. For reference, you can check out this codepen: http://codepen.io/timothyfernandez/pen/azXQPV Any assistance w ...

Navigational aids contained within buttons

Styling for Tooltip: .mainButtonContainer button:hover:after { background: none repeat scroll 0 0 rgba(255, 255, 255, 0.7); border-color: #093466; border-radius: 5px 5px 5px 5px; border-style: solid; border-width: 7px 2px 2px; bot ...

Adjusting the gridview headers to line up with a specific item and shifting the content of the item to the right

I am struggling with aligning the header and content in my gridview. I want the shirts to be underneath the header item, with the description moved to the left and the price 336 moved to the right. Something like this: https://i.sstatic.net/2i2IR.png Her ...

Encircle a circle within the Progress Tracker

Is there a way to create a ring around the circle in this progress tracker, similar to the image shown here? The progress tracker is based on You can view an example here. The CSS approach used was: .progress-step.is-active .progress-marker { backgrou ...

tips on adjusting margins or paddings in option select

How can I use the margin or padding options for my select dropdown? I tried using &nbsp; <select class="select"> <option value="100"></option> <option value="250">$593</option> ...