如何能使并列的三个div高度相同呢?
他们的高度是不确定的,这个我知道可以用js实现,不过不想用,想求教一下css能不能解决这个问题。
实现方法一:使用css Flexbox
<style>
.row {
display: flex; /* equal height of the children */
}
.col {
flex: 1; /* additionally, equal width */
}
M/style>
<div class=\"row\">
<div class=\"col\">...</div>
<div class=\"col\">...</div>
<div class=\"col\">...</div>
</div>
浏览器支持:http://caniuse.com/flexbox ; 演示:http : //jsfiddle.net/7L7rS/
方法二:表格布局Table layout
如果您仍然需要支持IE 8或9,那么您必须使用表格布局:
.row {
display: table;
}
.col {
display: table-cell;
width: 33.33%; /* depends on the number of columns */
}
演示:http : //jsfiddle.net/UT7ZD/
方法三:CSS网格Grid
HTML:
<div class=\"container\">
<div class=\"element\">{...}</div>
<div class=\"element\">{...}</div>
<div class=\"element\">{...}</div>
</div>
CSS:
.container {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.element {
border: 2px solid #000;
}
继续阅读与本文标签相同的文章
上一篇 :
js如何阻止表单提交
下一篇 :
开发者为什么不愿意参与开源贡献?不仅是钱的原因
-
第16问:Filecoin从DSN角度解读
2026-05-14栏目: 教程
-
C/C+从零基础到精通,究竟是如何快速完成的?其实只需要这6步!
2026-05-14栏目: 教程
-
谷歌再爆重大安全漏洞!华为却成最大赢家?网友:这谁还敢用!
2026-05-14栏目: 教程
-
Excel崩溃文件如何找回
2026-05-14栏目: 教程
-
又一外国巨头宣布退出中国,关闭120家店,网友:中国钱不好赚了!
2026-05-14栏目: 教程
