[英]How do I prevent my div layers from overlapping when the browser is resized?
I've just spent the last few weeks learning how to properly design a layout. 我刚刚花了几周时间学习如何正确设计布局。 I basically thought I had everything perfect with my website layout and was ready to go about transferring the coding to Wordpress... and then I accidentally resized my web browser and discovered that all of my div
layers were overlapping each other. 我基本上认为我的网站布局一切都很完美,并准备将编码转移到Wordpress ...然后我不小心调整了我的网页浏览器的大小,发现我所有的div
层都相互重叠。
Here's what it looks like: 这是它的样子:
Basically it looks as though it's mainly my center content div
that is being squeezed out, as well as my header image and navigation witch are in the same top div
. 基本上它看起来好像主要是我的中心内容div
被挤出来,以及我的标题图像和导航女巫在同一顶级div
。 My footer is also squeezed down as well. 我的页脚也被挤压了。 I've searched the internet for a solution to this problem and can't seem to find a thing. 我在互联网上搜索了这个问题的解决方案,但似乎无法找到答案。
How do I fix it so that my div
s stay in place when the browser is resized? 如何修复它,以便在调整浏览器大小时我的div
保持不变?
as Walter said your CSS would be helpful. 正如沃尔特所说,你的CSS会有所帮助。 But, the main problem is that the content in the div is overflowing to other divs because the the content's div cannot contain all the content. 但是,主要的问题是div中的内容溢出到其他div,因为内容的div不能包含所有内容。
In your css, try setting the div's overflow property to either auto (shows scrolls bars) or hidden (to just hide the content if it goes outside's the div) eg 在你的css中,尝试将div的overflow属性设置为auto(显示滚动条)或隐藏(只是隐藏内容,如果它超出了div),例如
overflow:auto;
or 要么
overflow:hidden;
I figured it out. 我想到了。 Turns out that the width of my center content margin was dictated by margins instead of just a direct width (ie. 500px). 事实证明,我的中心内容边距的宽度由边距决定,而不仅仅是直接宽度(即500px)。 So whenever the page was resized, the margins on the sides of the browser tried to stay as they were, thus making the entire column smaller. 因此,无论何时调整页面大小,浏览器两侧的边距都会保持原样,从而使整个列更小。 I just had to get rid of the margins and specify where I wanted the column to sit on the page and just justify a width for it. 我只需要去除边距并指定我希望列位于页面上的位置,并为其确定宽度。
Express your widths and font-sizes in ems. 用ems表示你的宽度和字体大小。 Here's a good calculator: http://riddle.pl/emcalc/ 这是一个很好的计算器: http : //riddle.pl/emcalc/
Percentages will work, too. 百分比也可以。
Check the css in stackoverflow, and try resizing the zoom level in your browser here - you'll see everything resizes nicely at any zoom level. 检查stackoverflow中的css,并尝试在此处调整浏览器中的缩放级别 - 您将看到在任何缩放级别上所有内容都可以很好地调整大小。
you can also try the min-width. 你也可以试试最小宽度。 i am assuming the center div is fluid and sidebars are fixed-width. 我假设中心div是流体,侧边栏是固定宽度。
Can you post some of your CSS? 你可以发布一些CSS吗?
The simplest way is to give all of your columns relatively sane width
settings so that the size of the browser window doesn't affect the size of your layout. 最简单的方法是为所有列提供相对合理的width
设置,以便浏览器窗口的大小不会影响布局的大小。 Getting fluid-width column(s) to behave is more complex and depends more on the specifics of your layout. 使流体宽度列表现得更复杂,更多地取决于布局的细节。
Check out the min-width
property. 查看min-width
属性。 Another option is applying another stylesheet when the viewport width is below x pixels with CSS3 Media Queries like so: 另一个选项是当视口宽度低于x像素时应用另一个样式表, CSS3 Media Queries如下:
@media all and (max-width: 30em) {
/* Alternative narrow styles */
}
or so: 或者:
<link media="all and (max-width: 30em)"
rel="stylesheet" href="narrow.css" />
CSS3 Media Queries are still not widely supported, so you might want to look into a solution that applies the "narrow" style sheet with JavaScript through the window.onresize
event. CSS3媒体查询仍然没有得到广泛支持,因此您可能希望通过window.onresize
事件查看通过JavaScript应用“窄”样式表的解决方案。 I'd recommend jQuery for such a solution. 我推荐jQuery用于这样的解决方案。
I Had the same problem if you have a width and height in your DIV Container it wont change except the width unless you put a min-width. 我有同样的问题,如果你的DIV容器中的宽度和高度除了宽度之外它不会改变宽度除外。 The problem I had was when I would make the browser window the divs would like go to the next line 我遇到的问题是当我在浏览器窗口中使用div时想要转到下一行
so what I did was in the container I set a height and width. 所以我所做的是在容器中设置高度和宽度。 Before I didn't set a height I let the divs determine the heights. 在我没有设定高度之前,我让div确定高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.