【问题标题】:what is the best practice in codes which has multiple display flex具有多个显示柔性的代码中的最佳实践是什么
【发布时间】:2022-09-28 15:09:45
【问题描述】:

如何避免在我的代码中重复 (display:flex, justify-content:center, aign-items:center)?我想使用它们,但我不想重复我自己(DRY 规则)。 有没有办法定义一个变量或包含这三行的东西? (不使用 SASS)

    标签: flexbox dry


    【解决方案1】:

    为代码中的所有弹性框创建一个模板类:

    .flexbox {
    display: flex;
    justify-content: center;
    align-items: center;
    }
    <div class="flexbox navbar-flexbox">*some code*</div>
    <div class="flexbox content-flexbox">*some code*</div>

    【讨论】:

      猜你喜欢
      • 2010-11-16
      • 1970-01-01
      • 2018-12-03
      • 2010-10-30
      • 2020-07-20
      • 2016-11-24
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      相关资源
      最近更新 更多