如何使用 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.
更多推荐
元素上的垂直空间位置:绝对
发布评论