Html 防止 div 在窗口调整大小时移动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4745923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
prevent div moving on window resize
提问by luca
I have a page with two divs "list_events" and "right_content" one next to each other. When I resize the window "right_content" moves down "list_events" but i dont want that! I dont want those two divs to move neither to scale down on window resizement..how can I achieve that?
我有一个页面,其中包含两个相邻的 div“list_events”和“right_content”。当我调整窗口大小时,“right_content”向下移动“list_events”,但我不想要!我不希望这两个 div 既不移动也不缩小窗口大小调整..我怎样才能做到这一点?
this is the code
这是代码
.list_events{margin-left:1em;float:left;}
.right_content{float:left;margin-left:1em;}
thanks Luca
谢谢卢卡
回答by somdow
first add a parent div/wrap and put those two divs of yours into it.
首先添加一个父 div/wrap 并将您的这两个 div 放入其中。
like so:
像这样:
<div id="wrap">
<div id="list_events"></div>
<div id="right_content"></div>
</div>
then you can try the
那么你可以试试
min-width(px/ems/ etc) on the parent/wrapper div like so:
父/包装器 div 上的 min-width(px/ems/ etc) 像这样:
#wrap{
min-width: 600px;
}
Overall, whatever size you add to the min-width itll scale the parent div down to the size specified.
总体而言,无论您添加到 min-width 的大小如何,它都会将父 div 缩小到指定的大小。
once the window is sized down past your specified size, itll behave like any other window.
一旦窗口缩小到超过您指定的大小,它就会像任何其他窗口一样运行。
this is my way of doing it.
这是我的做法。
回答by Mohammad
You can put this divs inside parent div with fixed width/height for that div, or you can determine a percentage width/height for each two divs.
您可以将此 div 放在父 div 中,该 div 具有固定的宽度/高度,或者您可以确定每两个 div 的宽度/高度百分比。