首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建具有弹性方向的表:列;?

如何创建具有弹性方向的表:列;?
EN

Stack Overflow用户
提问于 2021-07-16 19:17:15
回答 2查看 720关注 0票数 0

我的目标是用flex-direction: column;创建一个表。

代码语言:javascript
复制
Ticker Price  --.--
  --   Volume    --

index.html

代码语言:javascript
复制
<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>

styles.css

代码语言:javascript
复制
.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;使stockPricestockVolume看起来对齐。

我的实际结果是:text-align: center;不影响视图。

我所想的是:

  1. 使用HTML。据我所知,它不是移动友好的,特别是当第一列方向在下面,第二和第三列方向在右边。
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-07-16 19:29:08

这就是你要的!我用的是挠性方向柱

我在CSS中添加了相当多的内容,但这只是为了演示表正在做什么,所以如果您需要删除任何颜色/边距,或者更改了任何内容,请告诉我。

代码语言:javascript
复制
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; }
代码语言:javascript
复制
<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>

票数 0
EN

Stack Overflow用户

发布于 2021-07-16 19:50:01

下面是我对使用flex-direction: column创建表的问题的看法。通过这种方法,您可以使用div class="col"将数据列追加到价格-卷列的右侧。

代码语言:javascript
复制
.table {
  display: flex;
  column-gap: 5px;
  margin: 10px;
  border: 1px solid black;
  width: fit-content;
  width: -moz-fit-content;
}

.col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  row-gap: 5px;
}

.col div {
  background: beige;
}

.align-center {
  /* align-self: center; */
  text-align: center;
}

.align-right {
  /* align-self: flex-end; */
  text-align: right;
}
代码语言:javascript
复制
<div class="table">
  <div class="col">
    <div class="align-center">Ticker</div>
    <div class="align-center">--</div>
  </div>
  <div class="col">
    <div class="align-center">Price</div>
    <div class="align-center">Volume</div>
  </div>
  <div class="col">
    <div class="align-right">--.--</div>
    <div class="align-right">--</div>
  </div>
</div>

<div class="table">
  <div class="col">
    <div class="align-center">Ticker</div>
    <div class="align-center">--</div>
  </div>
  <div class="col">
    <div class="align-center">Price</div>
    <div class="align-center">Volume</div>
  </div>
  <div class="col">
    <div class="align-right">98.56</div>
    <div class="align-right">20</div>
  </div>
  <div class="col">
    <div class="align-right">72.03</div>
    <div class="align-right">13</div>
  </div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68414266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档