如何确保两个div具有相同的高度?

编程入门 行业动态 更新时间:2024-10-22 14:32:15
本文介绍了如何确保两个div具有相同的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我在一个包装器中并排有2个div。

Let's say I have 2 divs within a wrapper side by side.

<div id="wrapper"> <div id="primary"></div> <div id="secondary"></div> </div> #primary { width:50%; float: left; } #secondary { width: 50%; }

我如何确保div secondary始终与div primary具有相同的高度

How can I make sure div secondary always has the same height as div primary

推荐答案

不幸的是,如果不使用Javascript,则没有完美的方法来执行此操作,因为实际上两个div彼此都不了解。

Unfortunately there is no perfect method to do this without using Javascript as realistically the two divs know nothing about one another.

您的选择取决于您希望在视觉上实现的目标。

What your options are depends on what exactly you were looking to achieve visually.

通过Google快速搜索看起来很有希望的内容: www.vanseodesign/css/equal -height-columns /

A quick google search brought this up which looks quite promising: www.vanseodesign/css/equal-height-columns/

如果您可以专注于更现代的浏览器,则可以使用flexbox摆脱困境。有关示例等信息,请参见此帖子: css-tricks/fluid -width-equal-height-columns /

If you can focus on more modern browsers you may be able to get away with using flexbox. See this post for examples etc: css-tricks/fluid-width-equal-height-columns/

更多推荐

如何确保两个div具有相同的高度?

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

发布评论

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

>www.elefans.com

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