Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

html - css flex-box wrap but avoid region

I have a div that uses flex and wraps the items...

#container
{
    display: flex;
    flex-wrap: wrap;
}

The items wrap to the next row when they reach the end of the container. I need a region which the items will also wrap around. Here is an example of what I want...

enter image description here

The items(grey) wrap the the next row when they reach the region(red).

I am wondering if this possible to do using flex-box.

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check out this proof-of-concept which uses CSS Grid Layout. You can skip a region in the grid by using a pseudo element that is empty and is explicitly placed to create the effect that wrapped elements flow around it.

See demo below:

.grid {
  display: grid;
  grid-gap: 10px;
  grid-template-columns: repeat(6, [col-start] 1fr);
}

.grid>* {
  background-color: green;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.grid:after {
  content: '';
  grid-row: 1; /* row 1 */
  grid-column: 4/7; /* skip columns 4 to 6 */
  border: 1px dashed #ddd;
}
<div class="grid">
  <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>9</div>
  <div>10</div>
  <div>11</div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...