How can I make an iframe map fit 100% inside a div that changes height responsively from desktop to mobile?

Published on
September 22, 2023

To make an iframe map fit 100% inside a div that changes height responsively from desktop to mobile, you can follow these steps:

  1. Ensure that the div containing the map has a width of 100% so that it spans the entire width of its parent container.

  2. Set the height of the div to 0 initially. This will allow the height of the div to be determined dynamically based on the content inside it.

  3. Apply a padding-bottom hack to the div that will maintain its aspect ratio and adjust its height accordingly. The padding-bottom value should be calculated based on the aspect ratio of the map. For example, if the aspect ratio of the map is 16:9, you can set the padding-bottom to 56.25% (9 divided by 16 multiplied by 100).

  4. Position the iframe map absolutely inside the div, and set its width and height to 100%. This will make the map fill the entire div.

Here is an example of how you can implement these steps using HTML and CSS:

<div class="map-container">  <iframe src="https://your-map-url.com"></iframe></div>
.map-container {  position: relative;  width: 100%;  height: 0;  padding-bottom: 56.25%; /* Use the appropriate aspect ratio value for your map */  overflow: hidden;}.map-container iframe {  position: absolute;  top: 0;  left: 0;  width: 100%;  height: 100%;}

By following these steps, the iframe map will always fill the entire div, adjusting its height responsively as the div's height changes from desktop to mobile.

Additional Questions:

  1. How do I make an iframe map responsive in Webflow?
  2. What is the best way to embed a map in a Webflow website?
  3. Can I adjust the height of an iframe map in Webflow based on its content?