智能调整页面大小

发布于 2024-08-24 05:21:53 字数 278 浏览 4 评论 0原文

假设我有一个 HTML 页面,其中包含三个固定宽度的块(如果很重要,它们的高度可以有所不同),如图所示: alt text

我想让它的行为如下图所示:当浏览器屏幕宽度减小时,它不能将所有三个块放在一行中,第一个块下降。 alt text

是否有可能实现这种行为?最好只使用 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:
alt text

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.
alt text

Is it possible to achieve such behavior? Preferably with CSS only but any working solution would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

许你一世情深 2024-08-31 05:21:53
<div style="width: 100%;">
    <div style="display: inline-block; background-color: red; width: 200px;">DIV2</div>
    <div style="display: inline-block; background-color: yellow; width: 200px;">DIV3</div>
    <div style="display: inline-block; float: left; background-color: lightBlue; width: 200px;">DIV1</div>
    <br style="clear: left;">
</div>

这个有效。您将第 1 块作为最后一个块,并且只让该块剩下一个浮动。

<div style="width: 100%;">
    <div style="display: inline-block; background-color: red; width: 200px;">DIV2</div>
    <div style="display: inline-block; background-color: yellow; width: 200px;">DIV3</div>
    <div style="display: inline-block; float: left; background-color: lightBlue; width: 200px;">DIV1</div>
    <br style="clear: left;">
</div>

This one works. You put block 1 as the last one and only make that one float left.

情未る 2024-08-31 05:21:53

没有任何 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.

開玄 2024-08-31 05:21:53

使用带有 float:left 和固定宽度值的 div,

        <div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">    
3
    </div>        
        <div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">
        2    
    </div>
<div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">    
        1
    </div>

如下所示...
我知道第一个会正确,但这是我在不使用 javascript 的情况下可以做的最简单的事情。

Use divs with float:left and fixed width values

        <div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">    
3
    </div>        
        <div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">
        2    
    </div>
<div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">    
        1
    </div>

like so...
I am aware that the 1st one will go right but this is the simplest i can do without getting into javascript..

他不在意 2024-08-31 05:21:53

将这三个块全部放入一个 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.

月亮邮递员 2024-08-31 05:21:53
<div style="width: 100%;">
  <div style="width: 50px; float left;">DIV1</div>
  <div style="width: 50px; float left;">DIV2</div>
  <div style="width: 50px; float left;">DIV3</div>
  <br style="clear: left;" />
</div>
<div style="width: 100%;">
  <div style="width: 50px; float left;">DIV1</div>
  <div style="width: 50px; float left;">DIV2</div>
  <div style="width: 50px; float left;">DIV3</div>
  <br style="clear: left;" />
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文