简体   繁体   English

调整浏览器大小时DIV保持移动

[英]DIV keeps moving when I resize browser

So I'm coding a layout and I'm using a DIV to keep my iframe within the bounds of the layout. 因此,我正在对布局进行编码,并使用DIV将iframe保持在布局范围内。 The problem is my DIV keeps moving whenever I resize the browser. 问题是,每当我调整浏览器大小时,我的DIV都会移动。 I've looked around for answers, but none of them seem to help with the problem I have. 我到处寻找答案,但是似乎没有一个可以解决我遇到的问题。

Heres the website: 继承人的网站:

http://www.buymycookies.org/index.html http://www.buymycookies.org/index.html

This is my code: 这是我的代码:

<div style="position:absolute; top:280; left:560"> 
<iframe src="main.html" name="main" width="240" height="240" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" scrolling=auto allowtransparency=true>
</iframe>
</div>

As a side-note, I want to be able to control where my DIVs go because it needs to stay within the box of the layout. 作为一个旁注,我希望能够控制DIV的位置,因为它需要留在布局框中。

Thank you for helping! 感谢您的帮助!

You are using absolute positioning so your <div> containing the <iFrame> will always be 280 pixels from the top of the page and 560 pixels from the left. 您使用的是绝对定位,因此包含<iFrame> <div>总是从页面顶部开始为280像素,从页面顶部开始为560像素。

You should really read up on css positioning basics. 您应该真正阅读CSS定位基础知识。 A couple of good starting points could be 可能有几个很好的起点

Position absolute styles the element relative to the size of the whole page. 位置绝对样式相对于整个页面的大小来设置元素的样式。 thus when the page gets bigger the div moves to the left( left:560 ). 因此,当页面变大时,div向左移动( left:560 )。 You could use position relative instead: 您可以使用相对位置:

margin-top: -530px;
position: relative;

or 要么

position: relative;
top: -530px;

or 要么

margin-left: -120px;(because this div has a width of 240px)
position: absolute;
left: 50%;

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

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