1

Есть примерно такой код

<div>
   <p>1</p>
   <p>2</p>
   <p>3</p>
   <p>4</p>
   <p>5</p>
</div>

<style>
  div {
    width: 1000px;
    height: 100px;
  }

  p {
    display: block;
    width: 50px;
    height: 50px;
    outline: 1px solid black;
  }

</style>

Очень интересно как сделать так, чтобы блоки <p> которые не влезают в <div> по высоте, переносились вправо, и так далее, чтобы получилось вот так введите сюда описание изображения

2 ответа 2

3

Колонки

div {
  width: 400px;
  height: 100px;
  -moz-column-width: 50px;
  column-width: 50px;
  -moz-column-gap: 0;
  column-gap: 0;
  -moz-column-fill: auto;
  column-fill: auto;
  border: 1px solid red;
}

p {
  width: 50px;
  height: 50px;
  margin: 0;
  outline: 1px dotted black;
  outline-offset: -1px;
}
<div>
   <p>1</p>
   <p>2</p>
   <p>3</p>
   <p>4</p>
   <p>5</p>
</div>

3

Flexbox

div {
  width: 400px;
  height: 100px;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  border: 1px solid red;
}

p {
  width: 50px;
  height: 50px;
  margin: 0;
  outline: 1px dotted black;
  outline-offset: -1px;
}

div::after {
  content: "";
  height: 100%;
  width: 100%;
  flex-shrink: 1;
}
<div>
   <p>1</p>
   <p>2</p>
   <p>3</p>
   <p>4</p>
   <p>5</p>
</div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.