html - 如何使用 flex-direction: column; 创建一个表?
问题描述
我的目标是用flex-direction: column;
.
Ticker Price --.--
-- Volume --
索引.html
<div class="d-flex">
<div class="p-1">
Ticker
<div id="stockSymbol" class="font-weight-bold display-4">--</div>
</div>
<div class="d-flex flex-column p-1">
<div class="d-flex">
Price
<div id="stockPrice" class="p-1 font-weight-bold display-4">--.--</div>
</div>
<div class="d-flex">
Volume
<div id="stockVolume" class="p-1">--</div>
</div>
</div>
</div>
样式.css
.p-1 {
padding: 1rem;
}
.d-flex {
display: flex;
}
.flex-column {
flex-direction: column;
}
.font-weight-bold {
font-weight: bold;
}
.display-4 {
font-size: 2rem;
}
我的预期结果:我可以使用text-align: center;
使stockPrice
andstockVolume
看起来对齐。
我的实际结果:text-align: center;
不影响视图。
我考虑过的:
- 使用 HTML 表格。据我所知,它对移动设备不友好,特别是如果第一列方向在下方,而第二列和第三列方向在右侧。
解决方案
干得好!我使用了 flex-direction 列
我在 CSS 中添加了很多内容,但这只是为了演示表格在做什么,所以如果您需要删除任何颜色/边距;或任何改变让我知道。
html, body {
height: 100%;
margin: 0;
}
.grid2x2 {
min-height: 60%;
width: 60%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.grid2x2 > div {
display: flex;
flex-basis: calc(50% - 40px);
justify-content: center;
flex-direction: column;
}
.grid2x2 > div > div {
display: flex;
justify-content: center;
flex-direction: row;
}
.box { margin: 3px; }
.box1 { background-color: red; }
.box2 { background-color: orange; }
.box3 { background-color: purple; }
.box4 { background-color: grey; }
<div class="grid2x2">
<div class="box box1"><div>Price</div></div>
<div class="box box2"><div>--.--</div></div>
<div class="box box3"><div>Volume</div></div>
<div class="box box4"><div>--</div></div>
</div>
推荐阅读
- python - 如何在 Seaborn 中更改轴的字体大小?
- python - 如何更新我的 Mac 以使用最新版本的 Python?
- bitbar - 在 BitBar 上共享文件
- javascript - 如何在烧瓶应用程序中显示particles.js 库?
- ios - 类似于 Instagram 探索页面的复杂 UICollectionViewCompositionalLayout
- android - 使用服务帐户凭据模式的 Firebase 分发 android 应用程序的权限被拒绝
- google-analytics - 对自定义标签使用全局网站标签 (ga gtag) 代码
- verilog - 如何确定合成是在 Quartus 中完成的?
- ssh - Visual Studio 2017 和远程调试器 Msvsmon 之间的 ssh 隧道
- angular - 使用 NGXS 在 Angular 中删除嵌套数据的对象