Html 左右浮动的两个 div:如何在页面调整大小时将它们保持在同一级别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4082894/
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
Two divs floating left and right: How can I keep them on the same level when a page resizes?
提问by aarona
Given the following HTML:
鉴于以下 HTML:
<!DOCTYPE html>
<html>
<body>
<div id="container">
<div id="left" style="float: left; background-color: #777; width: 500px;">
Here is some content. Blah blah blah etc.
<div style="height: 50px;">Some more content</div>
And finally some more.
</div>
<div id="right" style="float: right; background-color: #aaa; width: 500px;">
Here is some content. Blah blah blah etc.
<div style="height: 50px;">Some more content</div>
And finally some more.
</div>
<div style="float: clear;"></div>
</div>
</body>
</html>
What can I do to div#container
or another tag to prevent div#right
from moving under div#left
when I resize the browser window such that the windows width is smaller then 1000px
?
当我调整浏览器窗口的大小使窗口宽度变小时,我可以做什么div#container
或另一个标签来防止div#right
移动?div#left
1000px
回答by Harmen
Set a min-width
to your container:
将 a 设置min-width
为您的容器:
#container {
min-width: 1000px;
}
回答by casablanca
Give the #container
DIV a min-width: 1000px
property, that way the parent will always be wide enough to hold both the children side-by-side.
给#container
DIV 一个min-width: 1000px
属性,这样父级总是足够宽,可以并排放置两个子级。
回答by Eswar
Container div not closed in your code. please check it once, and apply min-width:1000px;
容器 div 未在您的代码中关闭。请检查一次,并应用 min-width:1000px;
回答by rajh2504
http://www.w3schools.com/css/default.aspI learned all of my CSS here, there is a section on positioning that is quite helpful I suggest reading it for what your working on now as well as future projects.
http://www.w3schools.com/css/default.asp我在这里学习了我所有的 CSS,有一个关于定位的部分非常有用,我建议阅读它以了解您现在和未来的项目。
Try:
尝试:
#container {
position: relative;
}