使浮动div的高度相同

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

我有两个并排的div。我不知道他们的高度,它根据内容改变。有没有办法确保他们总是相同的高度,即使他们中的一个伸展,只有CSS?

I have 2 divs side by side. I don't know the height of them upfront, it changed according to the content. Is there a way to make sure they will always be the same height, even when one of them stretches, only with CSS?

我做了一个小提琴来显示。我想让红色和蓝色的div是相同的高度...

I made a fiddle to show. I want the red and blue divs to be the same height...

http:/ /jsfiddle/7RVh4/

这是css:

#wrapper { width: 300px; } #left { width:50px; background: blue; float:left; height: 100%; /* sadly, this doesn't work... */ } #right { width:250px; background: red; float:left; }

推荐答案

float,使用 display:table-cell 。你可能会发现一些旧的浏览器不理解这条规则。见下面:

You could try instead of using float, use display: table-cell. You might find some older browsers don't understand this rule however. See below:

#wrapper { display: table; // See FelipeAls comment below width: 300px; } #left { display: table-cell; width: 50px; background: blue; } #right { display: table-cell; width: 250px; background: red; }

更多推荐

使浮动div的高度相同

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

发布评论

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

>www.elefans.com

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