Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Chiều rộng flex container khi flex-flow là column wrap trong HTML

Nếu bạn có container với flex height & display flex, hãy làm theo nếu muốn children xếp theo cột.

Thay đổi cài đặt:

-webkit-flex-flow: column wrap;

Chrome tự động thêm khoảng cách giữa div và border top. Nếu không muốn tự động thêm khoảng cách, dùng:

margin-bottom:100%;

Điều này sẽ đẩy item lên.

.flex-container {
    position: fixed;
    height: 80%;// thay đổi chiều cao flex container thành 80%
    padding: 1;
    margin: 1; // thay đổi margin thành 1
    list-style: none;
    border: 7px solid red; // border solid red
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-flow: column wrap;
    justify-content: flex-start
    align-content: flex-start;
    align-items: flex-start
}
/** Just to show the elements */
body {
    margin: 0;
    padding: 0;
}
.flex-item {
    background: tomato;
    padding: 5px;
    width: 100px;
    height: 100px;
    margin-bottom: 100%;
    line-height: 150px;
    color: white;
    font-weight: bold;
    font-size: 3em;
    text-align: center;
}
<ul class="flex-container">
  <li class="flex-item">1</li>
  <li class="flex-item">2</li>
  <li class="flex-item">3</li>
  <li class="flex-item">4</li>
  <li class="flex-item">5</li>
  <li class="flex-item">6</li>
</ul>