How to display a side panel on the left and Google maps api canvas on the right, filling remainder of page?

一曲冷凌霜 提交于 2020-01-05 08:04:44

问题


I need to be able to have a side panel that fills the height of the page on the left and a map filling the rest of the page on the right. I would like the side panel to have a width of 300px, regardless of the size of the browser with the map to the right of it. Also, I am not able to move any of the divs within #panel, they are all just aligned one after the other. Here's my css:

body {margin:0;}
        #panel {height:100%; width:300px; position:absolute; padding:0;background-color:#8C95A0;}
            #div1 {padding:2px; text-align:center}
            #div2 {padding:2px; text-align:center}
            #div3 {padding:2px; text-align:center}
            #div4 {padding:2px; text-align:center}
            #div5 {padding:2px; text-align:center}
                #div5a {padding:2px; text-align:center}
                #div5b {padding:2px; text-align:center}
                #div5c {padding:2px; text-align:center}
            #div6 {padding:2px; bottom:0px; text-align:center}
        #map_canvas {height:100%; width:1200px; left:300px; position:absolute; padding:0;}

How can I make #map_canvas fill the rest of the page and how can I move my divs?


回答1:


<html>
    <head>
    <style>
        html,body { padding:0; margin:0; height:100%; }
        #panel { background-color: #DDD; position:absolute; top:0; left:0; bottom:0; width:300px; }
        #map_canvas { background:red; position:absolute; top:0; left:300px; right:0; bottom:0; }
    </style>
    </head>
    <body>
        <div id="panel"></div>
        <div id="map_canvas"></div>
    </body>
</html> 



回答2:


I was able to fix the two problems I enquired about in my question. Firstly, I was able to use relative positioning to move my divs around in the side panel instead of absolute. Secondly, I used the following css to make the map fill the rest of the screen, to the right of the side panel:

#map_canvas {height:100%; left:300px; right:0px; position:absolute; padding:0; margin:0;}



来源:https://stackoverflow.com/questions/10841762/how-to-display-a-side-panel-on-the-left-and-google-maps-api-canvas-on-the-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!