8

I have a display:flex row with 3 columns and flex-wrap is enabled. Between the columns are handle divs. When the columns are wrapped the handle divs should disappear. How can I use the wrap-state as a CSS selector to define attributes for that case, that the flex items are wrapped?

section {
  display: flex;
  flex-wrap: wrap;
  background-color: lightgray;
}
section * {
  margin: 1ex;
  background-color: white;
}
section * ~ * {
  margin-left: 0;
}
.handle {
  width: 1ex;
  background-color: gray;
}
aside, article {
  flex: 1;
  min-width: 5em;
}
#wide {
  width: 30em;
}
#narrow {
  width: 10em;
}
<section id="wide">
  <aside>
    left
  </aside>
  <div class="left handle"></div>
  <article>
    middle
  </article>
  <div class="right handle"></div>
  <aside>
    right
  </aside>
</section>
<hr>
<section id="narrow">
  <aside>
    top
  </aside>
  <div class="left handle"></div>
  <article>
    middle
  </article>
  <div class="right handle"></div>
  <aside>
    bottom
  </aside>
</section>

In non-wrapped mode I need to suppress the left margin and in wrapped-mode the top margin and the handles must be suppressed. How to know when being wrapped?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
ceving
  • 21,900
  • 13
  • 104
  • 178
  • 1
    This is one of these times where I wish we had [Element Queries](http://www.smashingmagazine.com/2013/06/25/media-queries-are-not-the-answer-element-query-polyfill/)… – janfoeh Feb 19 '15 at 15:37

1 Answers1

8

There is no CSS selector to select specifically wrapped flex items, unfortunately.

(It's unlikely that any such selector will be added, because it'd create weird circular dependencies. e.g. suppose a flex item wraps because it's too wide for the first line -- and then you select it & restyle it to be skinny, which means it no longer wraps. So then the selector should no longer match -- but then it's wide again, which makes it wrap... etc.)

dholbert
  • 11,386
  • 3
  • 42
  • 31
  • 2
    That is a stand problem of references. If you reference a headline, it is possible that the headline moves to the next page, just by referencing it. Those problems have been solved by TeX ages ago. – ceving Feb 20 '15 at 08:08
  • 5
    @ceving can you post a link to code or docs that explain the solution to this problem – derekdreery Oct 27 '15 at 09:21