CodexBloom - Programming Q&A Platform

HTML `<iframe>` Not Resizing Responsively in Chrome - implementing CSS Overrides

👀 Views: 56 💬 Answers: 1 📅 Created: 2025-06-11
html iframe css flexbox responsive HTML

I'm relatively new to this, so bear with me. I'm upgrading from an older version and I've been researching this but I'm stuck on something that should probably be simple. I've searched everywhere and can't find a clear answer. I'm having issues with an `<iframe>` element that isn't resizing responsively within a flexbox layout. I'm trying to display a Google Maps embed, but it stays at a fixed height, regardless of the container's size. In my CSS, I’ve set the container to use `display: flex;` and `flex-direction: column;`, but the iframe is not adapting to the container’s height changes. Here’s the structure of my HTML: ```html <div class="container"> <h1>My Map</h1> <iframe src="https://www.google.com/maps/embed?pb=!1m18!..." frameborder="0" style="border:0;" allowfullscreen></iframe> </div> ``` And the CSS I’m using: ```css .container { display: flex; flex-direction: column; height: 100vh; } iframe { flex: 1; width: 100%; height: auto; } ``` Despite trying different flex properties, the iframe height remains static and does not adjust to fill the available space. I’ve also attempted removing the `height` style altogether from the iframe, but it still doesn’t respond as expected. I’ve verified this behavior in Chrome Version 93.0.4577.82. I also noticed that when I inspect the iframe on the browser, it shows a computed height of 300px, which seems hardcoded. Is there something I’m missing in how I’m configuring the iframe or the surrounding flexbox? Any suggestions would be greatly appreciated. This is part of a larger service I'm building. I'd really appreciate any guidance on this. Any suggestions would be helpful.