Skip to content Skip to sidebar Skip to footer

Ignore Flex Container Children But Not Grandchildren

I have a simple flex element with some children, something like this: I am using flex wrap so, when screen goes smaller they stack. Now, I want to reload fourth and fifth element

Solution 1:

Use display:contents (https://css-tricks.com/get-ready-for-display-contents/) but pay attention to the support (https://caniuse.com/#feat=css-display-contents)

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

.containerdiv.flex-box {
  width: 200px;
  margin: 20px;
  padding: 20px;
  font-size: 40px;
  border: 1px solid;
}

.subcontainer {
  display: contents
}
<divclass='container'><divclass='flex-box'>one</div><divclass='flex-box'>two</div><divclass='flex-box'>three</div><divclass='subcontainer'><divclass='flex-box'>four</div><divclass='flex-box'>five</div></div><divclass='flex-box'>six</div></div>

Solution 2:

If the element is a child of a flex container, then it becomes a flex item. That's the general rule.

However, most browsers will ignore that rule when the child is absolutely positioned.

I'm not sure that's a useful solution in this case, but that's what you would have to do: absolutely position .subcontainer and make it flex container, so that the children become flex items.

Post a Comment for "Ignore Flex Container Children But Not Grandchildren"