如何使用Flex CSS最小宽度

时间:2018-07-02 09:37:34

标签: html css flexbox

我有一个Calendar应用程序,我想选择一个月间隔并显示它们。 当我选择最多3个月时,情况就是这样

enter image description here

...,当我想显示更多内容时,就这样。

enter image description here

我正在使用css flex,因此我希望浏览器具有最大宽度,以便很好地显示它们。我需要一种算法还是?

这是我的html

<div class="container-calendar1">
    <ca-month-calendar *ngFor="let selectedMonth of selectedMonths" [month]="selectedMonth"> 
    </ca-month-calendar>

  <ca-month-calendar>
  </ca-month-calendar>
</div>

和我的CSS文件

.container-calendar1{
    display: flex;
    flex: 2;
}

month-calendar {
    margin:20px;
}

2 个答案:

答案 0 :(得分:0)

使用flex-wrap: wrap会将弹性项目包装到多行中。

.container-calendar1 {
  display: flex;
  flex-wrap: wrap;
  flex: 2;
}

.month-calendar {
  margin: 20px;
} 
<div class="container-calendar1">
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
  <div class="month-calendar">
    Calendar
  </div>
</div>

答案 1 :(得分:0)

使用flex-wrap: wrap;并根据需要设置width:

查看示例:

.flex-container {
  display: flex;
  flex-wrap: wrap;
  width: 400px;
}

.flex-container > div {
  background-color: DodgerBlue;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}
<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
  <div>7</div>
  <div>8</div>
</div>