Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display flex - keeping last element in full width

Tags:

html

css

flexbox

I am trying to keep my 3d element with full width of the flex container. but not getting the reuslt. any one suggest me the right way for ie11 here?

.parent{
  border:1px solid red;
  display:flex;
  justify-content:space-between;
  padding:0 40px;
}

.child{
  flex:0 0 30%;
  border:1px dashed green;
}

.child.last{
/* not working */
  width:100%;
}
<div class="parent">
  <div class="child">one</div>
  <div class="child">two</div>
  <div class="child last">three</div>
</div>
like image 905
user2024080 Avatar asked Oct 31 '17 08:10

user2024080


People also ask

How do you make flex items occupy entire width?

When you want a flex item to occupy an entire row, set it to width: 100% or flex-basis: 100% , and enable wrap on the container. The item now consumes all available space.

How do I make my flex element not shrink?

default flex-shrink: 1; If there's not enough space available in the container's main axis, the element will shrink by a factor of 1, and will wrap its content. flex-shrink: 0; The element will not shrink: it will retain the width it needs, and not wrap its content.

How do I get my last FLEX item to end?

Therefore you could use margin-top: auto to distribute the space between the other elements and the last element. This will position the last element at the bottom. Likewise, you can also use margin-left: auto or margin-right: auto for the same alignment horizontally.

How do I fill the remaining space on my flexbox?

Use the flex-grow property to make a flex item consume free space on the main axis. This property will expand the item as much as possible, adjusting the length to dynamic environments, such as screen re-sizing or the addition / removal of other items.


1 Answers

To enable for the last child to wrap and be 100% wide, add flex-wrap: wrap to parent and use flex-basis on last child.

.parent{
  border:1px solid red;
  display:flex;
  flex-wrap: wrap;
  justify-content:space-between;
  padding:0 40px;
}

.child{
  flex:0 0 30%;
  border:1px dashed green;
}

.child.last{
  flex-basis: 100%;
}
<div class="parent">
  <div class="child">one</div>
  <div class="child">two</div>
  <div class="child last">three</div>
</div>
like image 62
Asons Avatar answered Oct 24 '22 16:10

Asons