在调整窗口大小时让div保持同一位置 [英] Making divs stay the same place when resizing window
本文介绍了在调整窗口大小时让div保持同一位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是代码:
HTML:
< div id =leftblock>
< / div>
< div id =rightBlock>
< / div>
CSS:
#leftblock {
margin-left:20%;
背景颜色:红色;
float:left;
height:100px;
width:3px;
}
#rightBlock {
margin-right:20%;
背景颜色:红色;
float:right;
height:100px;
width:3px;
}
确定我的意思,测试编辑器中的代码,然后尝试调整窗口大小。
解决方案
如果您不想让他们四处移动,请将元素放置在固定大小的父级容器。
CSS
#container {
width:1000px;
}
#leftblock {
margin-left:20%;
背景颜色:红色;
float:left;
height:100px;
width:3px;
}
#rightBlock {
margin-right:20%;
背景颜色:红色;
float:right;
height:100px;
width:3px;
HTML
< div id =container>
< div id =leftblock>
< / div>
< div id =rightBlock>
< / div>
< / div>
First of all im new programmer, so dont judge quickly :). Anyways ive been struggling with this problem for some time now. The problem is when im resizing(scaling whatever) the window, it messes around with ALL my elements. When resizing my website, you should just see less, than before. Not move around elements.
Here's the code:
HTML:
<div id="leftblock">
</div>
<div id="rightBlock">
</div>
CSS:
#leftblock {
margin-left: 20%;
background-color: red;
float: left;
height: 100px;
width: 3px;
}
#rightBlock {
margin-right: 20%;
background-color: red;
float: right;
height: 100px;
width: 3px;
}
To be sure what i mean, test the code in an editor, and then try resize the window.
解决方案
If you don't want them to move around, place the elements in a fixed size parent container.
CSS
#container {
width: 1000px;
}
#leftblock {
margin-left: 20%;
background-color: red;
float: left;
height: 100px;
width: 3px;
}
#rightBlock {
margin-right: 20%;
background-color: red;
float: right;
height: 100px;
width: 3px;
}
HTML
<div id="container">
<div id="leftblock">
</div>
<div id="rightBlock">
</div>
</div>
这篇关于在调整窗口大小时让div保持同一位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文