简体   繁体   English

调整浏览器大小时,div宽度100%不起作用

[英]Div Width 100% not working when resizing of browser

Basically, my 100% width Div wrappers aren't working right when I re-size the browser. 基本上,当我调整浏览器大小时,我100%宽度的Div包装器无法正常工作。 When you re-size the browser smaller than what the page design is, I get a horizontal scroll bar and it's not actually spanning full width. 当您将浏览器的大小调整为小于页面设计的大小时,我会看到一个水平滚动条,并且实际上并没有跨越整个宽度。 It's like it's just cutting off at some point. 就像是在某个时候切断。

Here is the link : Website Link 这里是链接: 网站链接

I've tried to fix this but it's just really confusing me why this is happening. 我已经尝试解决此问题,但这真的使我感到困惑,为什么会这样。 Can anyone shed some light on this problem? 任何人都可以阐明这个问题吗?

Thanks in advance. 提前致谢。

Mark 标记

I figured it out! 我想到了! I set width: 100% to min-width: 100% and that fixes the issues. 我将width:100%设置为min-width:100%,这解决了问题。

Your .wrap div has a fixed width of 1050px which is forcing the minimum width of the page to also be 1050px. 您的.wrap div的固定宽度为1050px,这迫使页面的最小宽度也为1050px。 This is why you are seeing scrollbars when the browser window is less than 1050px wide. 这就是为什么当浏览器窗口的宽度小于1050px时看到滚动条的原因。

.wrap {
  position: relative;
  margin: 0 auto;
  width: 1050px;
}

However, there is a reason why this width is fixed, because the margin:0 auto; 但是,固定宽度是有原因的,因为margin:0 auto; requires a fixed width div in order to centre the content. 需要固定宽度的div才能使内容居中。

If you would like your design to scale down for narrower screens, then I suggest that you look at using CSS Media Queries to create alternative rules for different browser/device widths. 如果您希望设计缩小到更窄的屏幕,那么建议您考虑使用CSS Media Queries为不同的浏览器/设备宽度创建替代规则。

Try resising this demo to see if it does what you want, and if so, work through the tutorial . 尝试调整此演示的大小,以查看它是否满足您的要求,如果需要,请按照本教程进行操作

Smashing Magazine also has a good media queries tutorial, especially if you are looking for alternative layouts for mobile devices. Smashing Magazine也提供了很好的媒体查询教程,尤其是在寻找移动设备的替代布局时。

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

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