简体   繁体   English

怎么做 <div> 填充整个屏幕除了导航栏

[英]How to make <div> fill whole screen except for navbars

I'm currently using Bootstrap, using the following template they provide: 我目前正在使用Bootstrap,使用他们提供的以下模板:

Bootstrap Dashboard Template Bootstrap仪表板模板

I like the header/navbar, and the sidebar. 我喜欢标题/导航栏和侧边栏。 I have removed all the content in the "main space" div , leaving it blank. 我删除了“主要空间” div中的所有内容,将其留空。 This is the div 's code (ignore the border; it's there for me to visualize what the div is doing): 这是div的代码(忽略边框;它可以让我看到div正在做什么):

<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. 我的目标是将Google地图嵌入此空白区域。 To do this, I need to create a div that fills the entire whitespace. 为此,我需要创建一个填充整个空格的div Ideally, I would like the div to bind to the edges of the window, so it doesn't overflow / create any scrolling. 理想情况下,我希望div绑定到窗口的边缘,因此它不会溢出/创建任何滚动。 I found that by hard-setting my height, it would result in overflow if I resized my Chrome window for example. 我发现通过硬设置我的高度,如果我调整了Chrome窗口的大小,就会导致溢出。 Is there a way to do this? 有没有办法做到这一点?

For example, look at http://www.renthop.com/ . 例如,请查看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. 编辑:这是一个jquery问题。 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%. 我对你的HTML和CSS做了一些改变,一个问题是因为bootstrap浮动他们不喜欢填充高度100%的项目。 You need to make the float container positioned absolute and its parent as relative to maintain it. 您需要将float容器定位为absolute,将其父容器设置为relative以保持它。 http://jsfiddle.net/RZb2D/3/ http://jsfiddle.net/RZb2D/3/

#maps_canvas {
 padding:0px;
 height:100%;
 position:absolute;
}
.row {
 height:100%;
 position:relative;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM