元素上的垂直空间位置:绝对

编程入门 行业动态 更新时间:2024-10-27 18:22:42
本文介绍了元素上的垂直空间位置:绝对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用 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.

更多推荐

元素上的垂直空间位置:绝对

本文发布于:2023-10-08 08:46:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472112.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   位置   空间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!