元素上的垂直空间位置:绝对 [英] Vertical space on elements with position:absolute

查看:135
本文介绍了元素上的垂直空间位置:绝对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 position:absolute 动态高度创建元素,只使用css占据垂直空间?

How can I make elements with position:absolute and dynamic height occupy vertical space using only css? Is there any trick with containers and display that I can use?

推荐答案

不幸的是,使用绝对定位方法,根据定义,元素不再占用空间。所以没有,只有通过CSS没有办法做到这一点。

Unfortunately, using absolute positioning means, by definition, that your element is no longer taking up space. So no, only through css there is no way to do this.

您当然可以使用jQuery(或简单的javascript)来完成此操作。我怎么做是每个垂直元素旁边有一个空格元素。将空格元素和绝对定位的垂直元素包含在相对定位的div中。在网页加载时,更改空格元素的高度以匹配垂直元素的高度。

You can of course use jQuery (or plain javascript) to accomplish this. How I'd do it is have a space element next to each vertical element. Enclose both the space element and the absolutely positioned vertical element in a relatively positioned div. On page load, change the height of the space element to match the height of the vertical element.

这篇关于元素上的垂直空间位置:绝对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆