How To Override Relative Positioning On Google Map
I have tried to add a Google Map to my Umbraco site using the code below. The Div #map_canvas
gets relative positioning from the api and as such doesn't display on the page. If I manually override this in the inspector with static positioning the map appears, but I have tried in various ways to permanently override this, using suggestions found elsewhere on Stack Overflow, but have had no success. Can anyone suggest a way to do this?
EDIT: Turnip, this is as close as I can get, given that the page inherits some Umbraco code and is displaying in Umbraco's preview window, but I assume that the problem wouldn't be there anyway.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.MasterTemplate2>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = null;
}<!DOCTYPE html>
<html>
<head>
<title>"testpage"</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" target="_blank" rel="nofollow noreferrer" href="/css/wsha-style.css">
<script src="~/umbraco/lib/jquery/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAbVhWKXQ2uj-n0lX1JsZh_DqG9RI-XDhE"></script>
</head>
<body>
<div id="map_canvas" style="height:100%;"></div>
<script>
$(document).ready(function () {
var map_position = new google.maps.LatLng(55.8735958,-4.3387407)
var map = new google.maps.Map(document.getElementById("map_canvas"), {
center: map_position,
zoom: 3
});
var marker = new google.maps.Marker({
position: map_position,
map: map,
title: 'Marker'
});
});
</script>
</body>
Answer
Short answer: replace height: 100% with height: 100vh or px you want.
The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to 'auto'.
See more at here
For further reading: the height property from W3C recommendation
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM