调整页面大小时防止 div 移动
我对 CSS 很陌生,我正在尝试启动并运行一个页面。我成功地生成了我认为不错的页面,直到我调整浏览器窗口的大小,然后一切都开始移动。我不知道为什么会这样!!
当我调整窗口大小时,我希望“对象”保留在原来的位置,但窗口大小要调整。例如,如果我将窗口的底角向上和向左拖动,我希望看到右下角的内容消失并出现滚动条,但左上角的对象将准确地保持在原来的位置。
当我通过向左拖动右侧尺寸来调整浏览器窗口大小时,会发生这种情况。 header和menubar中的内容,都是向下跳转的。然后我尝试了 overflow:hidden;
,但据我了解这一切都不是正确的方法。
我已经尝试过这个问题。我尝试为 main 的 div 标题设置 min-width:820px;
。那并没有解决问题。
I'm quite new to CSS and I'm trying to get a page up and running. I managed to successfully produce what I thought was a nice page until I resized the browser window then everything started to move around. I have no idea why this is happening!!
When I resize the window I would like the 'objects' to stay where they are but the window to resize. for example, if I drag the bottom corner of a window up and to the left I'd expect to see what was at the bottom right disappear and scroll bars to appear but the object in the top left hand corner would stay exactly where they are.
It happens when I resize the browser window by dragging the right size leftwards. The content in header and the menubar, they both jump down. Then I tried overflow: hidden;
, but as I understand all this is not the right way.
Please find the HTML and CSS here.
I already tried this question. I tried setting min-width:820px;
for div header of the main. That didn't solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
1 - 删除 BODY CSS 中的边距。
2 - 将所有 html 包装在包装器
3 - 定义包装器的 CSS:
这会将所有内容组合在一起,并在页面上居中。
1 - remove the margin from your BODY CSS.
2 - wrap all of your html in a wrapper
<div id="wrapper"> ... all your body content </div>
3 - Define the CSS for the wrapper:
This will hold everything together, centered on the page.
您可以使用两种类型的测量来指定宽度、高度、边距等:相对测量和固定测量。
相对
相对测量的一个例子是您所使用的百分比。百分比与其包含元素相关。如果没有包含元素,则它们是相对于窗口的。
另一种相对度量是 em,它与字体大小相关。
固定
固定测量的一个示例是像素,但固定测量也可以是 pt(点)、cm(厘米)等。固定(有时称为绝对)测量始终尺寸相同。像素始终是像素,厘米始终是厘米。
如果您要对尺寸使用固定测量值,则浏览器尺寸不会影响布局。
There are two types of measurements you can use for specifying widths, heights, margins etc: relative and fixed.
Relative
An example of a relative measurement is percentages, which you have used. Percentages are relevant to their containing element. If there is no containing element they are relative to the window.
Another relative measurement is ems which are relative to font size.
Fixed
An example of a fixed measurement is pixels but a fixed measurement can also be pt (points), cm (centimetres) etc. Fixed (sometimes called absolute) measurements are always the same size. A pixel is always a pixel, a centimetre is always a centimetre.
If you were to use fixed measurements for your sizes the browser size wouldn't affect the layout.
我宁愿使用静态宽度,如果您希望页面根据屏幕尺寸调整大小,您可以查看 媒体查询。
或者,您可以在标题、导航、内容等元素上设置最小宽度。
I'd rather use static widths and if you'd like your page to resize depending on screen size, you can have a look at media queries.
Or, you can set a min-width on elements like header, navigation, content etc.
您好,首先,您的 html 中似乎有许多“错误”,其中缺少结束标记,您可以尝试将
的内容包装在固定宽度
hi firstly there seems to be many 'errors' in your html where you are missing closing tags, you could try wrapping the contents of your
<body>
in a fixed width<div style="margin: 0 auto; width: 900px>
to achieve what you have done with thebody {margin: 0 10% 0 10%}