Reputation: 39
We are building a web application with google map that covers all the main page. It looks great but when I open it on another computer, with slightly different resolution or screen size, the map size does not change accordingly.
I tried working with "%" instead of "px" but it is even worse and the map disappears.
I found some solutions that use "!important" but it didn't work for me, can't figure out why.
Here is my CSS (Cascading Style Sheets) for the map:
#google-container {
position: relative;
width: 100%;
height: 200px;
background-color: #e7eaf0;
}
@media only screen and (min-width: 768px) {
#google-container {
height: 300px;
}
}
@media only screen and (min-width: 1170px) {
#google-container {
height: 710px;
}
}
#cd-google-map {
position: relative;
}
#cd-google-map address {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
padding: 1em 1em;
background-color: rgba(211, 104, 104, 0.9);
color: white;
font-size: 13px;
font-size: 0.8125rem;
}
@media only screen and (min-width: 768px) {
#cd-google-map address {
font-size: 15px;
font-size: 0.9375rem;
text-align: center;
}
}
Here is my html (the map is being built in the main.js file):
<section id="cd-google-map">
<div id="google-container"></div>
<div id="cd-zoom-in"></div>
<div id="cd-zoom-out"></div>
<div id="addNewReviewButton" ng-controller="NavCtrl">
<button style="border-color: transparent; background-color: transparent;">
<ng-md-icon icon="add_circle" style="fill: #d43f3a" size="120" ng-click="addNewReview()"></ng-md-icon>
</button>
</div>
</section>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAl8UrwCupLjkdVfx_IXugrryC8ES32Cz8&language=iw&?v=3.exp&sensor=false&libraries=places"></script>
<script src="js/main.js"></script>
Here is an image of how it looks on my device, when on others it fits perfectly:
Upvotes: 3
Views: 6599
Reputation: 551
I just resolved it you need to change to:
height: 100vh;
and to make these following changes:
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
Hope that help you as much it helped me.
Upvotes: 2
Reputation: 161334
It looks like your problem is this CSS:
@media only screen and (min-width: 768px) {
#google-container {
height: 300px;
}
}
If you remove that, you can use percentage sizing (or vh/vw sizing)
Upvotes: 2
Reputation: 7069
This gives you a fullscreen map layout.
parent is set to relative, then the IFRAME is treated as child of that parent with position:absolute
values.
padding-bottom: (height*100)/width
;
for e.g.:
padding-bottom: 56.22% /*(768*100)/1366) - common screen resolution.*/
.table {
width: 100%;
height: 100%;
position: relative;
}
iframe {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 100%;
padding-bottom: 56.22%;
}
<div class="parent">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3774.2135216027964!2d72.83238461524519!3d18.921940761713312!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3be7d1c73993eebd%3A0x9e8c8bfbd74a913a!2sGateway+of+India%2C+Apollo+Bandar%2C+Colaba%2C+Mumbai%2C+Maharashtra+400001!5e0!3m2!1sen!2sin!4v1450701184011"
frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
Upvotes: 1
Reputation: 400
You can use vw (viewport width) and vh (viewport height) instead of % like :
height: 100vh;
Upvotes: 7
Reputation: 17944
You may use absolute positioning to fit the whole container to the edges of the browser:
Markup
<div class="map">
the map is here ...
</div>
CSS
.map{
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
Upvotes: 1