html - 如何使用最小高度 div 制作响应式列视图?
问题描述
我的 div 上的高度可变的问题不允许 div 定位在适当的位置
我添加了一个问题作为代码片段来玩。
这是我想要的解决方案:
注意: div 具有可变高度,因此我无法删除 min-width 属性
我想让它响应,所以对于不同的设备它会有不同的列,所以我不能像下面这样使用(Html 类层次结构)
Row
Column
Column
Row
Column
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
.column {
float: left;
width: 50%;
padding: 10px;
}
.row:after {
content: "";
display: table;
clear: both;
}
</style>
</head>
<body>
<div class="row">
<div class="column" style="min-height: 400px; background:#bfaeae; border: 1px dotted;">
<h2>Column 1</h2>
</div>
<div class="column" style="min-height: 200px; background:#bfaeae; border: 1px dotted;">
<h2>Column 2</h2>
</div>
<div class="column" style="min-height: 200px; background:#bfaeae; border: 1px dotted;">
<h2>Column 3</h2>
</div>
</div>
</body>
</html>
解决方案
您可以使用 css 弹性框:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
.row {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
}
.column {
padding: 10px;
width: 50%;
}
</style>
</head>
<body>
<div class="row">
<div class="column" style="min-height: 400px; background:#bfaeae; border: 1px dotted;">
<h2>Column 1</h2>
</div>
<div class="column" style="min-height: 200px; background:#bfaeae; border: 1px dotted;">
<h2>Column 2</h2>
</div>
<div class="column" style="min-height: 200px; background:#bfaeae; border: 1px dotted;">
<h2>Column 3</h2>
</div>
</div>
</body>
</html>
推荐阅读
- javascript - 元素为数组时两个数组之间的区别
- ios - 在 Xamarin WKWebView 和 UIWebView 之间共享 cookie
- gradle - Gradle 在子项目中找不到类
- python - python - 如何从函数调用两个返回的局部变量以验证为python中另一个函数的条件?
- cassandra-3.0 - 选择查询的 Cassandra 时间戳行为
- javascript - D3 堆积条形排序 - 图表仅更新一次
- angular - 基于某些条件的动态路由器重用策略
- python - 在Python中按ID分组时计算数据框列的滚动平均值
- php - 我的表单提交php中的输入数据有问题
- python - 使用 Opencv 进行透视变换