I have a 2 column layout for the website, with the left fixed-width column and a right fluid-width Google maps that fills the rest of the width not taken by the left column.
Problem: However I cannot seem to get Google maps <div id="map_canvas">
to be fluid and take up the rest of the width. Did I set it up wrongly? Thanks!
HTML
<div id="main_container">
<div id="sidebar"></div>
<div id="map_container">
<div id="map_canvas"></div>
</div>
</div>
CSS
#main_container {
width: 100%;
height: 500px;
float: left;
clear: both;
position: relative;
z-index: 1;
}
#map_container {
height: 100%;
float: left;
position: relative;
}
#sidebar {
width: 270px;
float: left;
}
#map_canvas {
height: 100%;
min-width: 100px;
float: left;
display: block;
position: absolute;
z-order: 1000;
}
Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).
If you try to use style="width:100%;height:100%"
on your map div, as you have done by giving 100% height, you get a map div that has zero height. That's because the div tries to be a percentage of the size of the <body>
, but by default the has an indeterminate height.
There are ways to determine the height of the screen and use that number of pixels as the height of the map div, but a simple alternative is to change the <body>
so that its height is 100% of the page. We can do this by applying style="height:100%"
to both the <body>
and the <html>.
(We have to do it to both, otherwise the <body>
tries to be 100% of the height of the document, and the default for that is an indeterminate height.)
Re-adjusting your css values should resolve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With