【问题标题】:Adding space between Flex rows在 Flex 行之间添加空间
【发布时间】:2018-06-15 20:32:53
【问题描述】:

我在 Angular 5 组件中有这个 html:

.row>div {
  flex-basis: calc(50% - 20px) !important;
  /* width less horizontal margins */
  margin: 10px;
}
<div fxLayout="column">

  <div fxLayout="row">
    <button mat-raised-button color="accent">
          <mat-icon>play_button</mat-icon>
          Start Recording
        </button>
  </div>

  <div fxLayout="row">
  </div>

  <div fxLayout="row">
    <button mat-raised-button color="accent">
          <mat-icon>play_button</mat-icon>
          Stop Recording
        </button>
  </div>

  <div fxLayout="row">
  </div>

  <div fxLayout="row">
    <div fxLayout="column">
      <div>
        <mat-checkbox>Firefox</mat-checkbox>
      </div>

      <div>
        <mat-checkbox>Chrome</mat-checkbox>
      </div>

      <div>
        <mat-checkbox>Allow XPath</mat-checkbox>
      </div>
    </div>
  </div>

</div>

它呈现为:

我尝试添加这个 CSS 来增加元素之间的间距:

.row > div {
  flex-basis: calc(50% - 20px) !important; /* width less horizontal margins */
  margin: 10px;
}

但这不起作用 - 如何在元素之间添加垂直间距?

【问题讨论】:

  • 我从这里得到了 CSS:stackoverflow.com/questions/38506233/…
  • 可以用自定义属性覆盖现有的 flex 属性吗?
  • 老实说我不知道​​
  • 我参考了他们的文档,查看答案,希望对您有所帮助

标签: html angular css flexbox


【解决方案1】:

我删除了fxLayoutrow,并添加了一个自定义类来解决这个问题。

请参阅他们的文档以了解他们如何使用rowhttps://github.com/angular/flex-layout/wiki/fxLayout-API

如果您使用&lt;div fxLayout="row"&gt;,它将帮助您保持水平。

如果您使用&lt;div fxLayout="column"&gt;,它将如下图所示。

因此,最好不要使您的代码复杂化。所以你只能使用一个 column 完成它

这里是 sn-p。

.row {
  margin: 10px;
}
<div fxLayout="column">
  <div class="row">
    <button mat-raised-button color="accent">
          <mat-icon>play_button</mat-icon>
          Start Recording
        </button>
  </div>
  <div class="row">
    <button mat-raised-button color="accent">
          <mat-icon>play_button</mat-icon>
          Stop Recording
        </button>
  </div>
</div>
<div fxLayout="column">
  <div class="row">
    <mat-checkbox>Firefox</mat-checkbox>
  </div>

  <div class="row">
    <mat-checkbox>Chrome</mat-checkbox>
  </div>

  <div class="row">
    <mat-checkbox>Allow XPath</mat-checkbox>
  </div>
</div>

希望这是有用的。

【讨论】:

  • 如果这能解决您的问题,请打勾。干杯!
  • 是的,由于某种原因它不起作用,但我认为这是正确的想法,我会继续尝试,如果有效,将接受答案
  • 您添加了自定义行类?
  • 不,我没有添加自定义行类,但我会添加,而且它可能会起作用...不过,为了避免名称冲突,我会将其称为“行”以外的其他名称跨度>
  • 这方面有什么进展吗?
猜你喜欢
  • 1970-01-01
  • 2022-11-11
  • 2012-04-22
  • 2021-05-31
  • 2013-07-12
  • 2015-10-15
  • 2017-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多