让两个div具有相同的高度

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

我有两个这样的div:

I have two divs like that:

<div id="div1">ABC</div> <div id="div2">ABC DEF GHI JKL MNO</div> #div1 { width: 50px; background-color: red; float: left; } #div2 { width: 50px; background-color: green; float: left; }

我想使div1的高度与div2的高度相同.

And i'd like to make the height of div1 is the same height of div2.

我该怎么办?谢谢!

JSFIDDLE

推荐答案

演示

Demo

最简单的解决方案是将两个div都包装在一个div中并使其显示为flex;

the simplest solution is to wrapper both the divs in a div and make it display flex;

html

<div class="wrapper"> <div id="div1">ABC</div> <div id="div2">ABC DEF GHI JKL MNO</div> </div>

css

.wrapper { display: flex; }

更多推荐

让两个div具有相同的高度

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

发布评论

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

>www.elefans.com

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