div 中的两个 span 彼此相邻且不浮动

发布于 2024-08-03 15:57:18 字数 156 浏览 4 评论 0原文

我在一个div中有两个span。我想将它们彼此对齐。我通过将它们向左和向右浮动来做到这一点。问题是这些跨度具有可变的高度(当您单击“更多选项”时它们会向下滑动)。因此,当它们的高度在运行时发生变化(通过向下滑动)时,它们不会向下推其下方的元素。如果有一种方法可以在不浮动的情况下对齐它们,那就行了。

I've got two spans in a div. I want to align them next to each other. I'm doing this by floating them both left and right. The problem is that these spans have variable heights (they slide down when you click for 'more options'). So when their heights are changed during runtime (by sliding down), they won't push down the elements under them. If there's a way to align them without floating them, that would work.

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

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

发布评论

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

评论(3

假面具 2024-08-10 15:57:18

也许这些跨度后面带有“clear:both”的元素可以解决您的问题?

Maybe an element with "clear:both" after those spans will solve your problem?

梦幻之岛 2024-08-10 15:57:18

overflow:autooverflow:hidden 放在您的 div 上。这将强制 div 的大小适应内部浮动内容。

Put overflow:auto or overflow:hidden on your div. This will force the div to size to the floating contents inside.

总以为 2024-08-10 15:57:18

冒着获得大量反对票的风险,使用 ?

At the risk of getting massive downvotes, use a <table>?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文