How to make <div> fill whole screen except for navbars - html

I'm currently using Bootstrap, using the following template they provide:
Bootstrap Dashboard Template
I like the header/navbar, and the sidebar. I have removed all the content in the "main space" div, leaving it blank. This is the div's code (ignore the border; it's there for me to visualize what the div is doing):
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"
id="maps_canvas" style="border:2px solid red">
<!-- a Google Maps embed would be here -->
</div>
My goal is to embed Google Maps in this whitespace. To do this, I need to create a div that fills the entire whitespace. Ideally, I would like the div to bind to the edges of the window, so it doesn't overflow / create any scrolling. I found that by hard-setting my height, it would result in overflow if I resized my Chrome window for example. Is there a way to do this?
For example, look at http://www.renthop.com/. They have a map that does what I'm looking to do - it locks to the bottom right of the screen.
EDIT: This is a jquery problem. Problem now is, I can't seem to get both these functions to run. when I remove my $(document) function, the google function works no problem. When I include it, the entire thing falls over:
/*$(document).ready(function() {
/* confirm("im here");
/*$('#map_canvas').css({'height': (($(window).height()) - 114)+'px'});
$(window).resize(function(){
$('#map_canvas').css({'height': (($(window).height()) - 114)+'px'});
});
});*/
function initialize(){
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(40.749623,-73.9618013),
zoom:12,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);

I mad some changes to your HTML and CSS, one problem is because bootstrap floats items they do not like to fill a height 100%. You need to make the float container positioned absolute and its parent as relative to maintain it. http://jsfiddle.net/RZb2D/3/
#maps_canvas {
padding:0px;
height:100%;
position:absolute;
}
.row {
height:100%;
position:relative;
}

Related

How to make a paper-card scrollable

I'm using polymer's paper-card (I can't use paper-dialog because of this issue). How can I make it scrollable?
For example, in this code I would like to be able to scroll the card when it gets too large for the screen. Right now it just makes some of the content unreachable.
<paper-card>
<h2>[[someMessage]]</h2>
<div id="someReallyLongStuff"></div>
<paper-button raised on-click="doSomethingAndCloseCard">OK got it:)</paper-button>
</paper-card>
I've tried limiting the paper-card's size with max-height but that doesn't help.
EDIT
Here are photos of another example to clarify my problem:
In the first photo I have a small paper-card that fits the screen, but when it gets bigger it doesn't become scrollable, but goes out of page boundaries to make some of the content unreachable
window with small paper-card
window with longer paper-card that is too big for the page
I'm looking for something like paper-dialog-scrollable only for paper-card
!!!Update with code example at the bottom!!!
Paper-dialog
However, I used to work around that backdrop problem, related to the paper-dialog, with this answer that I found somewhere. I used this in a Polymer 1 project so I am not certain if it will still work in version 2. You definitely have to adapt the function.
<paper-dialog with-Backdrop on-iron-overlay-opened="patchOverlay"></paper-dialog>
// Fix with-backdrop for paper-doalog (Polymer1)
// https://github.com/PolymerElements/paper-dialog/issues/7
patchOverlay: function (e) {
if (e.target.withBackdrop) {
e.target.parentNode.insertBefore(e.target.backdropElement, e.target);
}
}
Paper-Card
If you are still looking to work with the paper-card Element and find yourself unable to change the width read further.
I have never tested that code but a presume that you will have to use the Polymer mixin for the paper-card. I don't think max-length is valid CSS better would be to use max-width or max-height.
paper-card {
--paper-card: {
max-width: 500px;
};
}
Update
I have added a code example using the basic paper-card provided by Polymer here
Long story short, I gave the text container a fixed height and added overflow auto to it. This way scroll bars will be added as soon as the text doesn't fit in it's container. This can be improved by adding the overflow only to the y-axes with "overflow-y: auto;"
// Load webcomponents.js polyfill if browser doesn't support native Web Components.
var webComponentsSupported = (
'registerElement' in document
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')
);
if (webComponentsSupported) {
// For native Imports, manually fire WebComponentsReady so user code
// can use the same code path for native and polyfill'd imports.
if (!window.HTMLImports) {
document.dispatchEvent(
new CustomEvent('WebComponentsReady', {bubbles: true})
);
}
} else {
// Load webcomponents.js polyfill
var script = document.createElement('script');
script.async = true;
script.src = 'https://cdn.rawgit.com/StartPolymer/cdn/1.8.1/components/webcomponentsjs/webcomponents-lite.min.js';
document.head.appendChild(script);
}
paper-card {
--paper-card: {
width: 100px;
box-sizing: border-box;
};
}
.card-content {
width: 200px;
height: 100px;
overflow: auto;
}
<!-- <base href="https://gitcdn.xyz/cdn/StartPolymer/cdn/v1.11.0/components/"> -->
<!-- <base href="https://cdn.rawgit.com/StartPolymer/cdn/v1.11.0/components/"> -->
<base href="https://rawcdn.githack.com/StartPolymer/cdn/v1.11.0/components/">
<link rel="import" href="iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="paper-card/paper-card.html">
<style is="custom-style">
</style>
<paper-card heading="Emmental" image="http://placehold.it/200x100/FFC107/000000" alt="Emmental">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
<script>
window.addEventListener('WebComponentsReady', function() {
});
</script>

Angular Page Height Directive updating incorrectly

I am making a directive to set the height of a div equal to the height of the browser if the height of the div is less than the height of the browser.
I have created the following directive:
(function() {
var directive = function ($log, $window) {
function evaluate(element) {
var height = element.prop("offsetHeight");
var pageHeight = $window.innerHeight;
if (height < pageHeight)
{
$log.info("element height is less than page height, changing element height.");
element.css("height", pageHeight);
}
}
return {
restrict: "A",
link: function (scope, element, attrs)
{
//call it one time on load to handle first display
evaluate(element);
$window.addEventListener("resize",
function() {
$log.info("Resize directive called: evaluating window size.");
//window size changed, check if we need to adjust the height
evaluate(element);
});
//add a watch to trigger when the inside of the div changes
scope.$watch(function() { return element[0].childNodes.length }, function(values) {
evaluate(element);
});
}
}
};
angular.module('bootstrapApp')
.directive('fullSize', ["$log", "$window", directive]);
})();
and it is used in the following way:
<body>
<fullsize-background-image-1></fullsize-background-image-1>
<navbar-1></navbar-1>
<div class="container-fluid">
<div class="row">
<left-sidebar-1></left-sidebar-1>
<right-sidebar-1></right-sidebar-1>
<div class="col-xs-12 main" id="main" full-size>
<div ng-view="" autoscroll="true"></div>
<footer-1></footer-1>
</div>
</div>
</div>
....
</body>
My problem is, on page load, thing was working perfectly (without the scope.$watch statement). However, when angular routed to a different page, that content replaced what is in the div#main element. Sometimes the height of the new page is greater than the height of the previous page, causing my hidden <left-sidebar-1> to show.
What I need to do is, on initial page load have my full-size directive evaluate what the height of main should be. Then, when the page changes, have it re-evaluate it and remove the property if the content is bigger.
thanks.

Center and enlarge google maps

This is the code:
#map_canvas {
height: 1000px;
text-align: center;
}
<div dojoType="dojox.mobile.ContentPane" style="overflow: auto;">
<div id="map_canvas"></div>
<!-- cambiare style -->
</div>
I tried to center with various css attributi but don't works.How i center and enlarge all map in panel?
You have to resize your map.
Try this
var mapOptions = {
center: new google.maps.LatLng(43.653226, -79.3831843),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
$('#map-canvas').fadeIn('slow', function() {
google.maps.event.trigger(map, 'resize');
}
Anish's code is working for me. (minor fix: map-canvas -> map_canvas) The map fills the width of the page and is 1000px high.
Looking at the screenshot, your map is filling the width of the window. You can tell this because the map control is all the way to the right of the screen in the upper corner. But for some reason, the map isn't fetching the tiles that it needs to fill itself. This usually happens when the map container is resized without triggering the google map resize event. Are you creating the map before the dojo parser runs? I put Anish's code inside the ready() function in dojoInit() and the map fills the screen when it is shown.
Sizing google maps to fill available space (not using absolute height and width) is tricky, but usually the problem is the height, not the width. I've written a series of blog post on google maps in worklight here: http://www.ibm.com/developerworks/community/blogs/dhuyvett

layerslider WP 100% width and height

Can someone please guide me how to get an image full screen so that it stays in the centre both horizontal and vertical like the link provided.
http://css-tricks.com/examples/FullPageBackgroundImage/progressive.php
I'm only after the background bit and i need the image in a div apposed to in the css like in the example as i am using it for a slider in wordpress.
In order to make your LayerSlider display at 100% height and width, leave the "Slider height" attribute in "Slider Settings" blank, and then use a script like the following to set the height:
<script type="text/javascript">
function resize()
{
var heights = window.innerHeight;
document.getElementById("layerslider_1").style.height = heights + "px";
}
resize();
window.onresize = function() {
resize();
};
</script>
Insert the script into your footer.php file before the closing body tag. If your slider ID isn't number 1, then change "layerslider_1" to the correct ID.
you can add style to the div element
<div style="background: url(images/xyz.jpg) no-repeat center center fixed;">...</div>
I just took the css from your sample page and copy/pasted!

Google Map Gets Cropped When Using Display:Inherit;

I am trying to hide/show Google Maps by switching between display:none; and display:inherit;. When I apply display:inherit to Google Maps, part of the map gets cropped and I am unsure why. How would I fix this while still using display:none;?
Link to example
//HTML
<button id="toggleMap">Toggle Google Map</button>
<button id="toggleImage">Toggle Image</button>
<div id="image">
<img src="http://jdm-digital.com/wp-content/uploads/2012/04/google-jquery-opt-465x346.jpg">
</div>
<div id="map" style="width:500px; height:500px; display:none;">
<div id="map_canvas" style="height:100%;"></div>
</div>
//JavaScript
$('#toggleImage').click(function() {
$('#image').css('display', 'inherit');
$('#map').css('display', 'none');
});
$('#toggleMap').click(function() {
$('#image').css('display', 'none');
$('#map').css('display', 'inherit');
});
If you create a map while it's hidden the API doesn't know how big it should be because the browser reports it has zero size. The API only loads enough tiles for a zero-size map, and positions the centre at (0,0) — the top-left corner.
When you unhide the map, tell the API to get the new size by triggering the resize event:
google.maps.event.trigger(map,'resize')
Documentation — scroll down to Events.
If i understand correctly you can give display:block instead of display:inherit
My solution was to use $('#map').append(mapHTML); whenever #toggleMap was clicked. This way allowed for the map to be created whenever #map becomes visible.
I feel that this approach is sort of hack-ish; If anyone has an alternative solution I'd definitely like to know about it.
//HTML
<div id="map" style="width:500px; height:500px; display:none;"></div>
//JavaScript
$('#toggleMap').click(function() {
$('#image').css('display', 'none');
$('#map').css('display', 'inherit');
var mapHTML = "<div id=\"map_canvas\" style=\"height:100%;\"></div>";
$('#map').append(mapHTML);
googleMap(); //Google Map's initialize() that would create the map
});