Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a div (flex item) from flex calculations?

Tags:

css

flexbox

I have an html layout that I cannot modify since it's a 3d party library.

I have four divs and I want them to be inside a flexbox like that:

1------2------3

(where 2 is in the center and 4 is not visible at all).

I have created an example here.

It seems that it mostly work as I want to apart from the fact that the last div messes up the center position of the item number 2. Is there a way I can completely "exclude" it from the flex array by css even though it is in HTML?

.fc-toolbar {
	background-color: #7CC2DD;
	color: white;
	height: 5rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.fc-left {
	order: 0;	
}

.fc-right {
	order: 2;
}

.fc-center {
	order: 1;
}

.fc-clear {

}
<div class="fc-toolbar">
  <div class="fc-left">
    <button type="button">
      <
    </button></div>
  <div class="fc-right">
    <button type="button">
          >
    </button>
  </div>

  <div class="fc-center">
    <h2>May 2016</h2>
  </div>
  <div class="fc-clear"></div>
</div>
like image 287
Ilya Chernomordik Avatar asked May 04 '16 08:05

Ilya Chernomordik


People also ask

How do I exclude items from Flex?

You can give the element position: absolute and it will be taken out of the flow, just as you would do with a non-flex element. You can find the updated jsfiddle here. The url to the link is pointing to codepen (not jsfiddle) which is giving a 404 error.

Can a Flex container also be a flex item?

Flexbox is inherently a one dimensional layout model. Flex items within a flex container can be laid out either horizontally or vertically, but not both. If you want to lay out items in both dimensions, you'll need to nest a flex container inside another one.

How to center a <Div> using Flexbox property of CSS?

How to center a <div> using Flexbox property of CSS ? 1 We use the property of display set to flex i.e. display: flex; 2 Align items to center using align-items: center; 3 The last step is to set justify-content to center i.e. justify-content: center;

What is the default value of the Flex order value?

The first flex item in the code does not have to appear as the first item in the layout. The order value must be a number, default value is 0. The flex-grow property specifies how much a flex item will grow relative to the rest of the flex items.

What are the Flex item properties?

The flex item properties are: 1 order 2 flex-grow 3 flex-shrink 4 flex-basis 5 flex 6 align-self More ...

What is the Order of flex items in a flex container?

The element above represents four blue flex items inside a grey flex container. The order property specifies the order of the flex items. The first flex item in the code does not have to appear as the first item in the layout. The order value must be a number, default value is 0.


1 Answers

You can give the element position: absolute and it will be taken out of the flow, just as you would do with a non-flex element.

You can find the updated jsfiddle here.

like image 65
fabio.sang Avatar answered Oct 24 '22 06:10

fabio.sang