How can I design a responsive square `div` block in Webflow that maintains a width of 33.333% when the browser is resized?

Published on
September 22, 2023

To design a responsive square div block in Webflow that maintains a width of 33.333% when the browser is resized, you can follow these steps:

  1. Create a new div block: Start by adding a new div block to your Webflow project. This will act as the container for your square block.

  2. Set the width and height: Select the div block you just created and set its width and height to the desired dimensions. For a square, you can set both the width and height to the same value, such as 300px.

  3. Set the aspect ratio: To make the square responsive, you'll need to use CSS padding hack. Add a new class to the div block by clicking on the "Add class" button in the Style panel. Then, go to the "Custom Code" tab within the class settings.

  4. Add the custom code: In the "Head" tag of the "Custom Code" tab, add the following code:

<style>    .square-div {        padding-top: 100%; /* this will maintain the square aspect ratio */    }</style>
  1. Apply the custom class: Go back to the Style panel and apply the custom class (square-div) to the div block.

  2. Adjust the width: To maintain a width of 33.333% when the browser is resized, you need to set the div block's width relative to its parent container. Select the parent container of the square div block and set its display property to "flex". Then, adjust the width of the square div block by setting its flex property to 0 1 33.333%.

By following these steps, your square div block will maintain a width of 33.333% when the browser is resized, while still maintaining its square shape.

Additional Questions:

  1. How do I make a responsive square div block in Webflow?
  2. Can I set a specific aspect ratio for a div block in Webflow?
  3. What is the CSS padding hack and how can I use it in Webflow?