左右浮动的两个 div:如何在页面调整大小时使它们保持在同一水平?
给定以下 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>
当我使用 div#container
或其他标记来防止 div#right
在 div#left
下移动时,我该怎么办调整浏览器窗口的大小,使窗口宽度小于 1000px
?
Given the following 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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为您的容器设置
min-width
:Set a
min-width
to your container:为
#container
DIV 指定min-width: 1000px
属性,这样父级始终足够宽,可以并排容纳两个子级。Give the
#container
DIV amin-width: 1000px
property, that way the parent will always be wide enough to hold both the children side-by-side.您的代码中的容器 div 未关闭。请检查一次,并应用 min-width:1000px;
Container div not closed in your code. please check it once, and apply min-width:1000px;
http://www.w3schools.com/css/default.asp 我学到了所有我的 CSS 在这里,有一个关于定位的部分非常有帮助,我建议您阅读它以了解您现在以及未来的项目。
尝试:
http://www.w3schools.com/css/default.asp I 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.
Try: