Stop the browser from pushing everything around when I resize

时光总嘲笑我的痴心妄想 提交于 2020-01-12 07:12:21

问题


How can I stop my whole site from falling apart while a user is resizing the browser window?

The site looks perfect - it only gets all mangled when it is resized to a smaller size.


回答1:


Put a fixed-minimum-width wrapper around it:

Before:

<html>
<body>
<!-- Your content -->
</body>
</html>

After:

<html>
<body>
<div style="min-width: 960px; margin: 0 auto;">
<!-- Your content -->
</div>
</body>
</html>

This will ensure that your page is always displayed as at least 960px minimum width (and will create a horizontal scrollbar if the browser window is narrower).

You may also choose to use width instead of min-width, if you want your page to always display as a certain width even if the browser is wider, too.




回答2:


Force a fixed size instead filling the available space. This will let your website always "look perfect".

The downside: Users with smaller resolution setting or who size the browser smaller will have to scroll left to right on your page. Also users with large widescreens will see a bunch of extra space on the sides.

Real solution, change your styling to allow the page to still look decent when sized smaller (down to whatever size you think your users will typically be at).




回答3:


I know im very late, but this now has really helped me, so thanks:)

What i used it on: https://codepen.io/Mike-was-here123/full/oGWxam/

<div style="min-width: 1920px; margin: 0 auto; max-height: 1080px;">


来源:https://stackoverflow.com/questions/4641436/stop-the-browser-from-pushing-everything-around-when-i-resize

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