【问题标题】:How do I make the sidebar fit the window and the google map to fit the rest of the screen?如何使侧边栏适合窗口和谷歌地图以适合屏幕的其余部分?
【发布时间】:2012-08-19 11:01:10
【问题描述】:

这是我正在开发的网站的链接:http://thoughtfi.com/practiceIMR3.html

我试图让侧边栏延长浏览器窗口的长度并使其宽度约为 200 像素,然后让地图填充浏览器窗口的其余部分。我花了很多时间弄乱css来让它工作,但没有任何运气。当我将地图 div 的 css 设置为屏幕的一部分时,它会切掉大部分地图。当我将滚动条的长度设置为 100% 时,它包含所有信息,并且没有单独的滚动条来延长页面的长度。

这是我的 CSS 目前的样子:

<style type="text/css">
html, body, #map_canvas {
    width:   800px;
    height:  600px;
}
#sidebar {
    width:200px;
    height:600px;
    overflow:auto;
}
</style>

这是我身体的重要部位:

<body onload="initialize_page()" style = "height:100%; margin:0">
    <button onclick="hide_markers_kml();">hide</button>
    <button onclick="unhide_markers_kml();">unhide</button>

    <table style="width:100%;">
        <tr>
            <td>
                  <div id="sidebar"></div>
            </td>
            <td>
                  <div id="map_canvas"></div>
            </td>
        </tr>
    </table>

【问题讨论】:

    标签: html css google-maps-api-3


    【解决方案1】:

    不要使用TABLE 进行布局,而是尝试使用绝对定位。例如,看我的小提琴,A simple 100% layout。诀窍是绝对定位侧边栏和内容,指定left、top、right 或bottom 属性,并让浏览器在需要时自动计算宽度和高度。

    在演示中,我将侧边栏设置为left: 0; width: 200px;,将内容设置为left: 200px; right: 0;。这会创建一个 200px 宽的侧边栏区域,并且浏览器会为内容区域计算页面的剩余宽度。

    【讨论】:

    • 嗯,顶部有两个按钮被文本覆盖,当我滚动时,它不仅仅是列表,而是整个网页。关于如何解决的任何想法? thoughtfi.com/practiceIMR4.html
    • 是的,@geocodezip 说的。此外,您需要指定top: 2em; bottom: 0; 并去掉height 属性(高度将根据top 和bottom 属性自动计算)。总而言之,#sidebar { position: absolute; right: 0; width: 200px; top: 2em; bottom: 0; overflow: auto; }。 (顺便说一句,top: 2em; 是为按钮腾出空间……top: 0; 也可以)
    • 另外,如果你想把它放在另一个网站或较小的容器中,只需将 BODY 标记的内容包装在 DIV 中,然后给 DIV position: relative; CSS 属性。砰,完成。
    猜你喜欢
    • 2020-03-25
    • 2017-04-15
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 2023-03-06
    • 2020-08-20
    相关资源
    最近更新 更多