html 垂直float,CSS:“float:bottom”如果有可用的垂直空间. “浮动:离开”否则...

根据您所需的浏览器支持级别,简单的媒体查询可以解决您的问题:

gt;

这是我看到的效果:

有关视口高度的相关代码段:

The ‘height’ media feature describes the height of the targeted display area of the output device. For continuous media,this is the height of the viewport including the size of a rendered scroll bar (if any). For paged media,this is the height of the page Box.

A specified cannot be negative.

有时我发现Mozilla开发者网络更容易访问,但在这种情况下,它们提供了basically the same information.

您是否需要支持无法呈现媒体查询的旧浏览器?编写一个javascript polyfill应该可以相当简单,特别是使用像jQuery这样的库.

编辑

我修改了我的代码示例,以更贴近您的问题.你评论说:

Jashwant: putting the div below the other is always preferred. So it’s only in the case that there’s space to the right but not at the bottom,that div2 should go to the right of div1. – Jonas

我还将宽度设置为400px,如示例所示.

现在只有在屏幕太短而不能垂直的情况下才会向左浮动,并且右侧有足够的空间来容纳两者.否则它总是垂直的.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值