智能调整页面大小
假设我有一个 HTML 页面,其中包含三个固定宽度的块(如果很重要,它们的高度可以有所不同),如图所示:
我想让它的行为如下图所示:当浏览器屏幕宽度减小时,它不能将所有三个块放在一行中,第一个块下降。
是否有可能实现这种行为?最好只使用 CSS,但任何可行的解决方案都很棒。
Suppose I have an HTML page with three blocks of fixed width (their height can vary if that's important), like shown on picture:
I would like to make it behave as shown on next picture: when browser screen width is reduced so it can't fit all three blocks in one line, first block goes down.
Is it possible to achieve such behavior? Preferably with CSS only but any working solution would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这个有效。您将第 1 块作为最后一个块,并且只让该块剩下一个浮动。
This one works. You put block 1 as the last one and only make that one float left.
没有任何 Javascript 技巧,几乎不可能让第一个块下降。另一方面,使用
float: left
制作最右边的水滴则很容易。It's virtually impossible to let the first block drop down without any Javascript trickery. Making the right-most one drop with
float: left
is easy on the other hand.使用带有 float:left 和固定宽度值的 div,
如下所示...
我知道第一个会正确,但这是我在不使用 javascript 的情况下可以做的最简单的事情。
Use divs with float:left and fixed width values
like so...
I am aware that the 1st one will go right but this is the simplest i can do without getting into javascript..
将这三个块全部放入一个 div 中,并将其宽度设置为 100%,当屏幕调整大小时,块将自动排列。
Put all these three blocks inside a div and set it's width to 100%, when the screen will resize the blocks will be arranged automatically.