简体   繁体   English

调整窗口大小时阻止元素移动

[英]Stop elements from shifting when resizing window

I've built a header bar for my page. 我已经为页面建立了标题栏。 It consists of the element and inside are some elements, , . 它由元素组成,内部是一些元素。 I can lay everything out nicely but when I resize the browser window everything starts to move and overlap in the header. 我可以很好地布局所有内容,但是当我调整浏览器窗口的大小时,所有内容开始移动并在页眉中重叠。 Giving the header, or even the body a fixed with like "width: 1000px" solves this, but that is screen-size dependent. 给标题,甚至正文一个固定为“ width:1000px”的像素都可以解决此问题,但这取决于屏幕尺寸。

How can I have my page such that any resizing of the browser window causes scroll bars to appear to view the hidden content, and where this would NOT be dependent on a hard-wired resolution in pixels. 我该如何设置页面,以使浏览器窗口的任何大小调整都可以显示滚动条以查看隐藏的内容,并且该位置不取决于以像素为单位的固定分辨率。

Give your main div (often your wrap div) a min-width: ...px . 给您的主div(通常是环绕div)一个min-width: ...px

Like this: 像这样:

<div class="wrap">
    <div class="header">...</div>
    <div class="content">...</div>
</div>

.wrap {
     width: 95%;
     min-width: 900px;
}

In the example above, the wrapper div will always be at least 900px. 在上面的示例中,包装div始终将至少为900px。 When the window gets resized to a smaller width, the scrollbars will appear. 当窗口调整为较小的宽度时,将显示滚动条。

If the screen is bigger than 900px, the div will have a 95% width. 如果屏幕大于900px,则div的宽度为95%。

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

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